urish / ngx-moment

moment.js pipes for Angular
MIT License
1.17k stars 154 forks source link

TimeAgoPipe doesn't support string dates when fullTemplateTypeCheck is enabled #204

Closed theodorejb closed 5 years ago

theodorejb commented 6 years ago

There are a bunch of places in my HTML templates that use the amTimeAgo pipe like this:

{{myObj.someDateProp | amTimeAgo}}

Where someDateProp is an ISO8601 date string. This has been working without any issues so far.

However, when I try to enable the fullTemplateTypeCheck Angular compiler option, I get an error saying "Argument of type 'string' is not assignable to parameter of type 'Date | Moment'."

It looks like this is because the transform method of TimeAgoPipe specifies a type of Date or Moment, even though the underlying code supports strings and numbers too.

https://github.com/urish/ngx-moment/blob/834d75f155749edc5d371987438214640a8fd3a6/src/time-ago.pipe.ts#L21

This can be fixed by changing the relevant type signatures in TimeAgoPipe to moment.MomentInput instead of Date | moment.Moment.

Note: according to the Angular docs the fullTemplateTypeCheck option "will default to true in the future" (see https://angular.io/guide/aot-compiler#fulltemplatetypecheck).

Did you search for duplicate issue? Yes

Environment: