我将Nuxt 3/ Vue 3 defineProps与TypeScript结合使用,并希望从TypeScript类型中推断类型支持类型。
import { User } from '~/types/types'
const props = defineProps({
users: {
type: Array, // User[]?
},
})在本例中,如何使users支柱成为User[]的一种类型
发布于 2022-09-28 15:19:23
使用Vue的PropType
import { PropType } from 'vue'
import { User } from '~/types/types'
const props = defineProps = ({
users: {
type: Array as PropType<User[]>
},
})发布于 2022-09-28 15:38:29
您还可以使用纯类型的语法:
import { User } from '~/types/types'
const props = defineProps<{users:User[]}>()https://stackoverflow.com/questions/73883956
复制相似问题