Jack
Jack

Reputation: 329

property not exist on type - vue with typescript

I am trying to convert the js code to ts. My attempt is as below.

<script lang="ts">
 export default {
  data() {
    return {
      isShow: false as boolean
    }
  },
  methods: {
    openCalendar() : void {
      this.isShow = true;
    },
  }
}
</script>

But when I run the app it's throws an error in the console saying Property isShow does not exist on type {open(): void;}. Where I was got wrong and how can I fix it?

Upvotes: 0

Views: 2273

Answers (1)

Boussadjra Brahim
Boussadjra Brahim

Reputation: 1

To get types inference try to wrap your options with Vue.extend({}) :

<script lang="ts">
import Vue from 'vue'  
export default Vue.extend({
data() {
    return {
      isShow: false as boolean
    }
  }
  methods: {
    openCalendar() : void {
      this.isShow = true;
    },
 },
})
</script>

Upvotes: 5

Related Questions