Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upProperty 'xxx' does not exist on type CombinedVueInstance ? #8721
Comments
|
It seems to be intentional, I guess so you can't accidentally access computed properties via a method? Line 34 in 3b43c81 edit: 540a38f, #5887 (comment) |
|
I don't understand. What bad would happen if i access computed properties via a method ? |
|
They don't exist yet: https://codepen.io/kaelwd/pen/pOErZw?editors=0011 |
|
Yeah I know, it is a bit silly. Just a guess as to why they might've done that. |
|
Same here.
Is there any way to access methods in |
|
Since this appears to be only a typing issue and not a runtime issue, there is an (ugly?) workaround available: cast
Additionally omit the |
|
Same here. Vue 2.5 has better type declaration support for TypeScript but this seems broken. |
|
Same problem for me |
|
I guess we should remove I also faced another use case which I need comprehensive data() {
return {
someFunc: () => {
this.someComputed() // `this` type here should be comprehensive
}
}
}As a similar case, But they probably breaks existing apps type checking as we need to explicitly declare |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
So is this the proposed solution at the moment? |
|
One workaround I had been using is to add an Interface for the Vue instance like this:
This will let you add typing for methods and $refs, does not seem to be any side effects. EDIT: I will add this too since I struggled to work with the types for nullable properties (late initialization) with Vue.extend. if you try to return a type | null that is initialized as null, the typings think its literally null and that it cannot be the type. Workaround is to cast the return again, which is annoying so I made a wrapper type. This works well if you have data that needs to be set in mounted, or is a component level data that maybe doesn't get initialized until a certain method is called (Form validator and Dialog reference in UI framework in my cases:
|
|
I had this error while working inside of a computed property. My data and computed were organized like this:
It would give me the same error ( However, when I declared what type would be returned by the function, the error went away:
Any time I've run into this error, this is the technique I used to fix it. I hope it helps someone else, too |
|
Declare the return type worked for me as well... But such strange behavior. |
|
FWIW, the error shows for me only in VSCode, but when compiling with |
|
Declare the return type worked for me sometimes, but turn to |
Same here. Odd behavior but it works nonetheless. I supposed having a return in TypeScript never hurts haha! |
|
This happens for all my methods and data properties. What's the solution? UPDATE: Apparently, you have to annotate the return type for your computed methods, otherwise all your |
|
Thanks @IAMtheIAM, your hint solved it for me. I was having the issue with |
|
I had this issue until I gave all my computed properties return types. I had to alter my expectation to follow this pattern: expect((wrapper.vm as any).subtotalFormatted).toBe('£1,234.56');Yuk! I hope this can be resolved soon. |
Ugly fix provided in: vuejs/vue#8721 (comment)
|
I have this issue - but 'computed' statement is nowhere in my dummy project. I'm using just 'methods'. Basically reproduction is the same as the original post at the top. I tried the solution with the type declaration, this didn't help me (ts 3.8.3) |
|
Having the same issue when using the new Vue.js Composition API with vscode-insiders. The code compiles without TS errors but vscode shows an error nonetheless. // setup(props, context) {
watch(
() => context.root.$q.screen.width,
() => setMiniState(undefined)
)Details
Possible related issues: #23987, #29511 #32573 #34999 Type declaration didn't work here either as a workaorund. So this failed too in vscode: watch(
(): number => context.root.$q.screen.width,
() => setMiniState(undefined)
) |
|
I also have this problem in vscode |
|
Typescript 3.9 has made this even worse, I have to specify return types for methods too now. |
|
I'm very new to TypeScript. I tried all the advice here without any success, but I managed to build on @danjohnso's workaround to "solve" this with intersection types:
I have no idea if doing that is bad, but everything seems to work fine. Edit: My issue is with properties from mixins not being recognized. |
|
Solution from @tipsy solved it for me. My use case was using interface HomeMapState {
plants: Plant[]
}
export default (Vue as VueConstructor<Vue & HomeMapState>).extend({
name: 'Home',
computed: {
...mapState<HomeState>('home', {
plants: (state: HomeState) => state.plants,
}),
plantData(): Array<Plant | {}> {
if (this.loading) {
return new Array(5).fill({})
}
return this.plants
},
}
})
|
|
I'm having this problem with Jest unit tests as well |
|
Annotating the computed properties got rid of the error in vscode. However, I still get an error when running |
|
Typescript can't find methods unless computed properties are annotated, see vuejs/vue#8721






Version
2.5.17
Reproduction link
Steps to reproduce
What is expected?
How can i fix it ?
What is actually happening?
Property 'initData' does not exist on type 'CombinedVueInstance<Vue, {}, {}, {}, Readonly<{ msg: string; }>>'.