vue: Vuejs type inference does not work with TS 3.4.x
Version
2.6.10
Reproduction link
https://github.com/Patcher56/ts3.4.x-vuejs-issue
Steps to reproduce
- create a new vue typescript project (without class syntax)
vue create test-ts - open
src/components/HelloWorld.vue - add a data variable and try to access it in a computed property
What is expected?
No errors (as the data is defined)
What is actually happening?
Typescript error 2339 telling me
Property 'test' does not exist on type 'CombinedVueInstance<Vue, {}, {}, {}, Readonly<{ msg: string; }>>'.

I think this has something to do with the changed type inference in Typescript 3.4.x.
Important: Change vetur settings to use workspace dependencies to show errors directly in vscode, else you will only get the error when using yarn serve.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 10
- Comments: 27 (12 by maintainers)
One workaround is assigning a return type to computed
Best workaround is to use the new Vue Composition API. It is a lot cleaner for typescript and works also with typescript versions > 3.3.4000.
Unfortunately it also happens if you have a validator on a prop, and it isn’t fixed with the annotation workaround:
Breaks our entire build, easily 100+ errors after stepping up from TS v3.3.3333 to v3.4.4. Too bad, too, because this version of TS introduced some handy features for exactly what I’m working on right now… 😩
Looks like TS3.4 has multiple inference issue…
The minimal repro:
Also spotted another failure:
The catch-all type signature of component
is causing union type to fail checking.
I need more time for investigation…
/cc @HerringtonDarkholme @ktsn
We also had a component start throwing a lot of errors after upgrading from TS
3.3.3333to3.4.5Thanks to this comment, went back and checked that component and, sure enough, one of the computed properties did not have a return type annotated. With that annotation added, the build compiled without issue.
Per the TS comment, perhaps the docs would be best updated as “you will need to annotate the return type on methods like
renderand those incomputed” (though the docs are already pretty clear on the cases that are now breaking)I wonder if properties in
dataare supposed to become properties of the instance when using TypeScript?(Note: the two examples I gave are not fixed by the workaround mentioned)