From: Cathrine Vaage Date: Mon, 15 Nov 2021 03:09:00 +0000 (+0100) Subject: fix(types/sfc): fix withDefaults type inference when using union types (#4925) X-Git-Tag: v3.2.22~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=04e58351965caf489ac68e4961ef70448d954912;p=thirdparty%2Fvuejs%2Fcore.git fix(types/sfc): fix withDefaults type inference when using union types (#4925) --- diff --git a/packages/runtime-core/src/apiSetupHelpers.ts b/packages/runtime-core/src/apiSetupHelpers.ts index 292b2f42f7..fc1866af95 100644 --- a/packages/runtime-core/src/apiSetupHelpers.ts +++ b/packages/runtime-core/src/apiSetupHelpers.ts @@ -127,20 +127,21 @@ export function defineExpose(exposed?: Record) { type NotUndefined = T extends undefined ? never : T type InferDefaults = { - [K in keyof T]?: NotUndefined extends - | number - | string - | boolean - | symbol - | Function - ? NotUndefined - : (props: T) => NotUndefined + [K in keyof T]?: InferDefault> } -type PropsWithDefaults = Base & - { - [K in keyof Defaults]: K extends keyof Base ? NotUndefined : never - } +type InferDefault = T extends + | number + | string + | boolean + | symbol + | Function + ? T + : (props: P) => T + +type PropsWithDefaults = Base & { + [K in keyof Defaults]: K extends keyof Base ? NotUndefined : never +} /** * Vue `