1

我将Angular 4.0.0Typescript 2.2.1datejs 1.0.0-rc3一起使用。每当我尝试编译应用程序 ( npm start ) 时,都会收到以下打字稿错误:

ERROR in [at-loader] ./src/app/services/dates.service.ts:9:56 
    TS2339: Property 'getDay' does not exist on type 'number'.

编码:

/** dates.service.ts **/
import {Injectable} from "@angular/core";

@Injectable()
export class CalendarService {

    DateJs: IDateJSStatic = <any>Date;

    getDay() {
            var day = this.DateJs.parse('2017-04-01').getDay();
            return day;
    }

}

查看文件node_modules/@types/datejs/index.d.ts,函数的声明parse()显然是Date

/** Converts the specified string value into its JavaScript Date equivalent using culture-specific format information. */
parse(dateString: string): Date;

有人知道发生了什么吗?

4

1 回答 1

0

使用格式方法。文档:https ://github.com/abritinthebay/datejs/wiki/Format-Specifiers

DateJs: IDateJSStatic = Date as any;

getDay() {
    const day = new DateJs('2017-04-01')
    return day.format('l')
}
于 2017-09-01T01:03:36.447 回答