vuejs / composition-api-rfc

Vuepress render for the Composition API RFC
https://vue-composition-api-rfc.netlify.com
104 stars 37 forks source link

How To Use Types In Props #27

Open bekalshenoy opened 4 years ago

bekalshenoy commented 4 years ago

The Documentation Is Limited For How To Use Types In Props. It Can Help Me To Use Interface As A Type For A Prop Instead Of Using Object By Default.

ycmjason commented 4 years ago

Don't think it relates to the composition api itself. But I suppose you can type the validator.

defineComponent({
  props: {
    magic: (x: Magic) => true
  }
})
jefrydco commented 4 years ago

@bekalshenoy You can type it this way:


type ComponentProps = {
  value: string
}

defineComponent<ComponentProps>({
  // Props will automatically has `ComponentProps` type
  setup(props) {}
})