Reputation: 4656
I started a vue.js project with typescript and I want to use single file components, and not class-styled ones. I constantly get error TS2339 when trying to reference my components' data, with the "this" keyword:
export default {
data(){
return { x: 10 as number };
},
methods: {
foo() {
if(this.x > 10) {
return this.x;
}
}
}
}
It always leads to "TS2339 Property 'x' does not exist on type 'CombinedVueInstance
Upvotes: 0
Views: 495
Reputation: 815
The reason why it's not working is briefly explained in the official documentation.
You need to use the following syntax in a SFC
<script lang="ts">
import Vue from 'vue'
export default Vue.extend({
})
</script>
Upvotes: 2