Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuxt `defineProps` from TypeScript types

I'm using the Nuxt 3 / Vue 3 defineProps with 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 prop a type of User[]?

like image 876
thisismydesign Avatar asked Jul 20 '26 06:07

thisismydesign


1 Answers

Use Vue's PropType

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

const props = defineProps = ({
  users: {
    type: Array as PropType<User[]>
  },
})
like image 170
thisismydesign Avatar answered Jul 23 '26 02:07

thisismydesign



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!