Closed davidgiga1993 closed 2 years ago
your likely undelying problem is that you don't annotate the computed property's return type, which is required when using Options API & TS.
https://vuejs.org/guide/typescript/options-api.html#typing-computed-properties
Can'T 100% verify as I can't run the reproduction right now, but I'm willing to bet that it's this.
your likely undelying problem is that you don't annotate the computed property's return type, which is required when using Options API & TS.
https://vuejs.org/guide/typescript/options-api.html#typing-computed-properties
Can'T 100% verify as I can't run the reproduction right now, but I'm willing to bet that it's this.
I just checked and you're correct, it does work when I provide a type for the computed property. However: Why does it work when I have at least one - non related - property set? I would expect the error to either appear always or never since the prop has nothing to do with the rest.
That's kinda hard to figure out or explain. The typings for Option API's this
are inherently circular: the type if this
depends on the return values of options like the computed properties, as those become properties on this
, but the return type of your un-annotated computed property depends on the this
type.
This generates a wide range of possible combinations of things that inherit from other things in a circular fashion which usually break the types if return annotations are not provided, but sometimes, TS can figure it out.
Vue version
3.2.37
Link to minimal reproduction
https://github.com/davidgiga1993/vue-ts-issue
Steps to reproduce
Create a new project using typescript as preset
Edit the default
HelloWorld
component: We remove the defaultmsg
property and add a single data item which gets used in a computed propertyRun the project:
npm run serve
What is expected?
No errors, the component should just work
What is actually happening?
As soon as the component has no property anymore, any references to items defined in the
data
section doesn't work anymore:It doesn't matter which prop is set, you can just add a dummy
and it will start working again
System Info
Any additional comments?
No response