Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'Moment' is not assignable to type 'Date'. Property 'toDateString' is missing in type 'Moment'

I have configure moment with my angular2 application, and when i tried to assign the date of this week saturday to a date type variable,

  case "weekend":         
        this.fromDate =  moment().startOf('week');

It shows an error saying,

Type 'Moment' is not assignable to type 'Date'.   Property 'toDateString' is missing in type 'Moment'

I have imported moment in my component as follows,

import * as moment from 'moment/moment';
like image 684
Sajeetharan Avatar asked Feb 10 '17 14:02

Sajeetharan


1 Answers

startOf:

Mutates the original moment by setting it to the start of a unit of time

so it returns a moment object. Use toDate() if you need to convert to JavaScript Date.

case "weekend":         
    this.fromDate =  moment().startOf('week').toDate();
like image 51
VincenzoC Avatar answered Nov 12 '22 12:11

VincenzoC