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.
There are a bunch of places in my HTML templates that use the
amTimeAgo
pipe like this: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 ofTimeAgoPipe
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
tomoment.MomentInput
instead ofDate | 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:
moment
version? 2.22.2moment-timezone
? No