vue-lynx / withDefaults

Function: withDefaults()

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

Vue <script setup> compiler macro for providing props default values when using type-based defineProps declaration.

Example usage:

withDefaults(defineProps<{
  size?: number
  labels?: string[]
}>(), {
  size: 3,
  labels: () => ['default label']
})

This is only usable inside <script setup>, is compiled away in the output and should not be actually called at runtime.

Type Parameters

Type Parameter
T
BKeys extends string | number | symbol
Defaults extends InferDefaults<T>

Parameters

ParameterType
propsDefineProps<T, BKeys>
defaultsDefaults

Returns

PropsWithDefaults<T, Defaults, BKeys>

See

https://vuejs.org/guide/typescript/composition-api.html#typing-component-props

Defined in

node_modules/.pnpm/@vue+runtime-core@3.5.30/node_modules/@vue/runtime-core/dist/runtime-core.d.ts:362