0

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

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.