[Vue + Typescript] Property does not exist on type in computed function
See original GitHub issueVersion
2.5.17
Reproduction link
https://codesandbox.io/s/10l5yrl9rq
Steps to reproduce
Codesandbox seems not support typescript code intelligense in *.vue
, the file is src/index.vue
Here is the code:
<script lang="ts">
import Vue from 'vue'
interface TestInterface {
a: string
}
export default Vue.extend({
props: {
prop1: {
type: Object as () => TestInterface,
},
},
computed: {
computed1() {
return this.prop1.a
}
}
})
</script>
What is expected?
Typescript compiler will not complaint
What is actually happening?
Property ‘prop1’ does not exist on type ‘{ computed1(): any; }’.
Is there any way to solve this problem?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:19 (2 by maintainers)
Top Results From Across the Web
Resolve "Property does not exist on type 'Vue'" error
Show activity on this post. Here is an example of class based component: import { Component, Vue, Watch } from 'vue-property-decorator' @ ...
Read more >Typescript: Property 'foo' does not exist on type 'Vue' - Sami C.
When I added a type on my setter val the error was no longer present! set(val: boolean) { (this as any).$emit('input', false); },....
Read more >Property '$wait' does not exist on type 'Create Component ...
I am learning TypeScript and I am getting an error I don't really know how to handle it. TS2339: Property '$wait' does not...
Read more >♂️ ♀️ Vue 3 error with using TypeScript: property X does ...
♂️ ♀️ Vue 3 error with using TypeScript: property X does not exist on type 'EventTarget' · Simple Errors (3 Part Series) ·...
Read more >Property does not exist on type data - Ionic Vue
ts to a property. I successfully get the results, however, when I import the function and I try to pass the values to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Let me left a note for everyone who’re confused as i am: annotate ALL return types of computed properties.
Please read https://vuejs.org/v2/guide/typescript.html You should do the following things to make type inference works.
strict: true
ornoImplicitThis: true
for compiler option.