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

Data properties not found and/or incorrectly typed in TypeScript 3.6.2 #10455

Closed
kjleitz opened this issue Aug 29, 2019 · 5 comments
Closed

Data properties not found and/or incorrectly typed in TypeScript 3.6.2 #10455

kjleitz opened this issue Aug 29, 2019 · 5 comments

Comments

@kjleitz
Copy link

kjleitz commented Aug 29, 2019

Version

2.6.10

Reproduction link

https://jsfiddle.net/keegan_openbay/nhvemx32/ (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

@posva
Copy link
Member

posva commented Aug 30, 2019

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

@ktsn
Copy link
Member

ktsn commented Aug 30, 2019

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 } {
  // ...
}

@ktsn
Copy link
Member

ktsn commented Aug 30, 2019

I've filed it on TypeScript repo.
microsoft/TypeScript#33164

@ktsn
Copy link
Member

ktsn commented Sep 11, 2019

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

@dasDaniel
Copy link

dasDaniel commented Jun 24, 2022

I'm still seeing this with TypeScript 4.5.5 on vue 2.6.14

my workaround is to use (this as Vue) instead of this

for example

watch:{
  myVar(){
    (this as Vue).myMethod()
  }
}

with a component definition (in the same file) like:

declare module "vue/types/vue" {
  interface Vue {
    myMethod: () => void
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants