Argument of type 'Date' is not assignable to parameter of type 'string'

I had a similar problem.

After researching I found three useful links :

Date variable works, but functions on it do not

Converting string to date issue

Invalid argument 'date format' for pipe 'DatePipe'?

What I then did was to declare my variable as type Date in the "export class" component like this :

start: Date

and then later on in a function I used it like this to populate the date variable:

start = new Date(Date.now());

Judging on the error you are receiving I assume that your function "startOfDay()" is returning a string so you would then have to change your code as follows.

start: new Date(startOfDay(new Date(attendance.dayAt)))

reason for this being that if "start" is a date then you have to use the function new Date() to assign a date to it. Date then takes string as input and returns a date and assigns it to variable "start". Hope this helps :)


I have a situation where a date value is being returned from a web service as a JSON string and a date is being cast into a Date type property in typeScript. This causes 'Type 'string' is not assignable to type 'Date'' error to be shown during the compilation.

One work-around I've found is to define client side property as 'any' type (instead of :Date). This allows JSON to nicely cast into a date and no error is shown during the compilation.