Vue: Data properties not found and/or incorrectly typed in TypeScript 3.6.2

Created on 30 Aug 2019  ·  4Comments  ·  Source: vuejs/vue



Reproduction link (be aware that JSFiddle does not show TypeScript compiler errors)

Steps to reproduce

  • use TypeScript >= 3.6.1-beta (currently stable at 3.6.2)
  • have at least one prop
  • correctly type all your methods
  • use a non-string data property in your component options

What is expected?

Normal behavior; the data property is correctly typed and found on the instance.

What is actually happening?

Errors arise because:

  • in methods, the data properties are not found on the component type.
  • in watch, the data properties are typed string | WatchOptionsWithHandler<any> | WatchHandler<any>.
  • in computed, the data properties are typed (() => any) | ComputedOptions<any>.

Screen Shot 2019-08-29 at 6 50 52 PM
Screen Shot 2019-08-29 at 7 00 23 PM
Screen Shot 2019-08-29 at 7 10 17 PM

bug typescript

Most helpful comment

I've filed it on TypeScript repo.

All 4 comments

It's indeed not working anymore while it was on 3.5.3. Not sure if it's an upstream problem or not but something broke in our types

I'm just looking into it. Still not sure whether it's upstream bug or not. But annotating data's this type can be a workaround:

data(this: any): { loading: boolean; fade: boolean } {
  // ...

I've filed it on TypeScript repo.

TypeScript v3.6.3 has been released and it solves this issue.

Was this page helpful?
0 / 5 - 0 ratings