Home  >  Q&A  >  body text

Nuxt `defineProps` from TypeScript types

I'm using Nuxt 3 / Vue 3 defineProps and TypeScript and want to infer types prop types from TypeScript types.

import { User } from '~/types/types'

const props = defineProps({
  users: {
    type: Array, // User[]?
  },
})

In this example, how do I make the users property be of type User[]?

P粉895187266P粉895187266354 days ago782

reply all(1)I'll reply

  • P粉070918777

    P粉0709187772023-10-31 00:24:00

    Using Vue’sPropType

    import { PropType } from 'vue'
    import { User } from '~/types/types'
    
    const props = defineProps = ({
      users: {
        type: Array as PropType<User[]>
      },
    })
    

    reply
    0
  • Cancelreply