From 04e58351965caf489ac68e4961ef70448d954912 Mon Sep 17 00:00:00 2001 From: Cathrine Vaage Date: Mon, 15 Nov 2021 04:09:00 +0100 Subject: [PATCH] fix(types/sfc): fix withDefaults type inference when using union types (#4925) --- packages/runtime-core/src/apiSetupHelpers.ts | 25 ++++++++++---------- test-dts/setupHelpers.test-d.ts | 15 ++++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/packages/runtime-core/src/apiSetupHelpers.ts b/packages/runtime-core/src/apiSetupHelpers.ts index 292b2f42..fc1866af 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 `