"时刻"类型不能指定为"日期"类型.'Moment'类型中缺少属性'toDateString'

Saj*_*ran 6 momentjs typescript angular

我用angular2应用程序配置了一下,当我试图将本周星期六的日期分配给日期类型变量时,

  case "weekend":         
        this.fromDate =  moment().startOf('week');
Run Code Online (Sandbox Code Playgroud)

它显示错误说,

Type 'Moment' is not assignable to type 'Date'.   Property 'toDateString' is missing in type 'Moment'
Run Code Online (Sandbox Code Playgroud)

我在我的组件中输入了以下内容,

import * as moment from 'moment/moment';
Run Code Online (Sandbox Code Playgroud)

Vin*_*zoC 15

startOf:

通过将原始时刻设置为单位时间的开始来突变原始时刻

所以它返回一个时刻对象.使用toDate(),如果你需要转换成JavaScript日期.

case "weekend":         
    this.fromDate =  moment().startOf('week').toDate();
Run Code Online (Sandbox Code Playgroud)