-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Typescript: Private fields in classes on data properties cause failed type verification since 3.0.8 #3815
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
Comments
This is caused by the feature auto unwrap refs on public instance type of After putting, type
The sturcture of type It seems that the break could not be fixed easily because of the feature auto unwrapping and limitation of typescript. Easiest way to solve this problem is |
@tonyfinn You can also use |
Duplicate of #2981 |
Version
3.0.11
Reproduction link
https://github.com/tonyfinn/vue-ts-error
Steps to reproduce
There are two projects in the reproduction example.
ts-type-error
uses Vue 3.0.8 (but 3.0.11 is also broken).works
uses Vue 3.0.7. The two projects are otherwise identical.Both are using Vue CLI, so can be built by running
npm run serve
What is expected?
Both projects would build or fail with the same result.
What is actually happening?
works
builds correctly and runs correctly.ts-type-error
fails to build with the following error:The issue appears to be with the private fields. Inside the component methods,
this.foo
is not of typeFoo
as of 3.0.8, only of a type that is effectively the public fields/interface ofFoo
only. This means that when you useFoo
as a type in a function declaration, passingthis.foo
is rejected, as it is missing the private fields as far as the type checker can see.This appears to be a type checker issue only, if you change clickHandler to:
Then you can observe that the log messages are printed upon clicking the text at runtime.
The text was updated successfully, but these errors were encountered: