Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
theodorejb opened this issue Oct 23, 2018 · 0 comments

Comments

@theodorejb
Copy link
Contributor

theodorejb commented Oct 23, 2018

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.

transform(value: Date | moment.Moment, omitSuffix?: boolean): string {

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:

  • Angular version? 7.0.2
  • TypeScript version? 3.1.6
  • moment version? 2.22.2
  • Are you using moment-timezone? No
  • Are you using the angular-cli? No
  • Using Rollup/Webpack/System.js/Ionic/similar? Webpack
@theodorejb theodorejb changed the title Support passing string to amTimeAgo pipe when fullTemplateTypeCheck is enabled TimeAgoPipe doesn't support string dates when fullTemplateTypeCheck is enabled Nov 15, 2018
@urish urish closed this as completed in #206 Dec 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant