Nuxt `defineProps` from TypeScript types
P粉895187266
P粉895187266 2023-10-30 11:35:06
0
1
866

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粉895187266
P粉895187266

reply all(1)
P粉070918777

Using Vue’sPropType

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

const props = defineProps = ({
  users: {
    type: Array as PropType<User[]>
  },
})
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template