Description
TypeScript Version: 3.4.1, 3.4.2, 3.4.3, 3.5.0-dev.20190410
Search Terms: Vue 3.4 typing
Code
It's not clear to me if this is a problem with Typescript or with Vue's types, but it started happening in Typescript 3.4 with no change to Vue.
I have a repo that reproduces the problem here: https://github.com/mrozekma/typescript-vue-problem. This was created using Vue CLI with just Typescript enabled, followed by upgrading to Typescript 3.4 and adding the following to the default export in src/App.vue
:
computed: {
foo: function() {
return this.bar;
},
},
data: function() {
return {
bar: true,
};
},
Expected behavior:
Should build without errors.
Actual behavior:
This builds fine with 3.3.3, and according to Visual Studio Code it's valid (even version 1.33.0 with bundled Typescript 3.4.1), but if I try to build with any Typescript 3.4.x I get:
ERROR in src/App.vue
19:19 Property 'bar' does not exist on type 'CombinedVueInstance<Vue, {}, {}, {}, Readonly<Record<never, any>>>'.
17 | computed: {
18 | foo: function() {
> 19 | return this.bar;
| ^
20 | },
21 | },
22 | data: function() {
The type of this
on line 19 is unexpectedly sparse. The second template argument should be the return type of the data
function, and looks correct in Code's tooltip of that line:
CombinedVueInstance<Vue, {
bar: boolean;
}, {}, {
foo: boolean;
}, Readonly<Record<never, any>>>
Playground Link:
Related Issues:
Possibly related to #30442, as it mentions a regression with intersection types, which ComputedVueInstance
is.