Skip to content

wevu / index / withDefaults

函数: withDefaults()

withDefaults<T, BKeys, Defaults>(props, defaults): PropsWithDefaults<T, Defaults, BKeys>

定义于: packages/wevu/src/macros.ts:135

withDefaults 为 defineProps 指定默认值(仅类型层)。 默认值会影响可选/必选推导,但不生成运行时代码。

类型参数

T

T

BKeys

BKeys extends string | number | symbol

Defaults

Defaults extends InferDefaults<T>

参数

props

DefineProps<T, BKeys>

defaults

Defaults

返回

PropsWithDefaults<T, Defaults, BKeys>

示例

ts
const props = withDefaults(defineProps<{
  title?: string
  size?: 'sm' | 'md' | 'lg'
}>(), {
  title: 'Empty',
  size: 'md',
})

Released under the MIT License.