-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
Typescript: Computed properties cannot correctly infer even simple return types #7394
Comments
This is a known limitation of the type system, you have to manually annotate computed properties. Likely a wontfix, otherwise it would have already been implemented as part of 2.5. @HerringtonDarkholme or @ktsn might be able to provide more insights. |
This is documented in https://vuejs.org/v2/guide/typescript.html#Annotating-Return-Types |
@yyx990803 @HerringtonDarkholme Thanks for the info here. Will keep an eye on the underlying TS issue. |
For future readers coming from google search: |
Version
2.5.13
Reproduction link
https://github.com/wadetandy/vue-computed-typescript-error
Steps to reproduce
After cloning the above repo, run
yarn install && yarn dev
. Yarn will load webpack and attempt to build the project, at which point the typescript compilation will fail on the ErrorReproduction.vue file. Alternatively, open it up in vscode or something else with good typescript integration to see the same errors.What is expected?
In the affected file, I would expect all of the computed methods to behave with standard type inference due to their very straightforward return types. Indeed when I access the
this
member, it shows all data members, methods, and even the correct values for the computed properties themselves!What is actually happening?
Any time I try to return a data member from the computed properties, the method gives a type error:
and the value itself gives an error:
(note the above no longer includes computed properties or data members)
Additionally, hovering my type view over even the
simpleString()
method shows a return type ofany
, even though it should be trivial for vue to figure this type out from the simple string return.The text was updated successfully, but these errors were encountered: