Sajeetharan
Sajeetharan

Reputation: 222682

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';

Upvotes: 12

Views: 32570

Answers (1)

VincenzoC
VincenzoC

Reputation: 31502

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();

Upvotes: 31

Related Questions