[Vuejs]-Vue3 prop String or PropType

0๐Ÿ‘

โœ…

Use a function expression for that prop type:

const Component = defineComponent({
  props: {
    book: {           ๐Ÿ‘‡
      type: [String, () => Object as PropType<Book>]
    }
  },
  mounted() {
    const isBook = (obj: any): obj is Book => 'title' in obj // eslint-disable-line @typescript-eslint/no-explicit-any

    if (isBook(this.book)) {
      console.log(this.book.title)
    }
  }
})

Leave a comment