fahmiduldul
fahmiduldul

Reputation: 1130

Pass Component Props to Object in Vue Typescript

I'm trying to pass props value in vue component to object as index like code below.

export default defineComponent({
  props:{
    pollId:{type: String}
  },
  data(){
    return{
      poll: polls[this.pollId]
    }
  }
})

But when I do this, I got error like these: error

the compiler keeps assuming that my props are undefined even I've specified it above.

is there a way to fix this? without sacrificing

Upvotes: 2

Views: 961

Answers (1)

fahmiduldul
fahmiduldul

Reputation: 1130

It's actually as simple as adding required property in props

export default defineComponent({
  props:{
    pollId:{required:true,type: String}
  },
  data(){
    return{
      poll: polls[this.pollId]
    }
  }
})

Upvotes: 1

Related Questions