【问题标题】:Typescript errors on Angular 4 and DatejsAngular 4 和 Datejs 上的打字稿错误
【发布时间】:2017-08-20 00:33:15
【问题描述】:

我将 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()的声明显然是日期

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

有人知道发生了什么吗?

【问题讨论】:

    标签: typescript datejs angular4 typescript2.2


    【解决方案1】:

    使用格式化方法。文档: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')
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-13
      • 2017-12-22
      • 2016-05-01
      • 1970-01-01
      • 2016-04-07
      • 1970-01-01
      • 2021-09-23
      • 2018-04-15
      相关资源
      最近更新 更多