composition-api-rfc icon indicating copy to clipboard operation
composition-api-rfc copied to clipboard

How To Use Types In Props

Open bekalshenoy opened this issue 5 years ago • 2 comments

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.

bekalshenoy avatar Apr 28 '20 06:04 bekalshenoy

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

defineComponent({
  props: {
    magic: (x: Magic) => true
  }
})

ycmjason avatar Apr 28 '20 11:04 ycmjason

@bekalshenoy You can type it this way:

type ComponentProps = {
  value: string
}

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

jefrydco avatar Aug 16 '20 18:08 jefrydco