betterDefine
Stability:
stableWith enabling betterDefine, imported types are supported in <script setup> type-based-macros.
| Features | Supported |
|---|---|
| Vue 3 | ✅ |
| Nuxt 3 | ✅ |
| Vue 2 | ✅ |
| TypeScript | ✅ |
Basic Usage
vue
<script setup lang="ts">
import { type BaseProps } from './types'
interface Props extends BaseProps {
foo: string
}
defineProps<Props>()
</script>ts
export interface BaseProps {
title: string
}⚠️ Limitations
Complex types
Complex types are not supported in some key places. For example:
What are Complex Types?
- All utility types
- Built-in types
- All types from
type-festpackage. typeofkeyword.- ...
- Index Signaturets
interface Type { [key: string]: string } - Generics will be ignored directly
What are Key Places?
- The names of props.
ts
// ✅
defineProps<{
foo: ComplexType
}>()
// ❌
defineProps<{
[ComplexType]: string
}>()- The names of emits.
ts
interface Emits {
(event: 'something', value: ComplexType): void // ✅
(event: ComplexType): void // ❌
}