Joni Joni - 2 months ago 34
TypeScript Question

installed typings for datejs not working for me

I am new to Typescript which I started because of Angular 2. I would like to use the Javascript library datejs.

To use it in my Angular 2 project I installed datejs through npm and confirmed it is listed in my package.json. In addition I installed the typings that are available through DefinitelyTyped (dt). When I do "typings list" it shows that the datejs typings are included globally.

Then in my component I have :

import 'datejs'
//declare var Date: any;

but when I run tsc then it complains because apparently datejs is not extending the Date object, for example:

error TS2339: Property 'next' does not exist on type 'Date'.

However, when I uncomment the declaration of Date it works just fine. From my understanding this means that I am then not using the typings that I install. What am I missing here?

I guess what complicates things here is that datejs does not export module since it extends the default Javascript Date object.



Use IDateJSStatic, example in my homecomponent:

export class HomeComponent implements OnInit {
    pageTitle: string = 'Home';
    DateJs: IDateJSStatic = <any>Date;

    constructor() { }

    ngOnInit(): void {


Hope that helps