From 91e54dbc41f902c61581ca88222f8164e68a17a0 Mon Sep 17 00:00:00 2001 From: David Matter Date: Mon, 16 Oct 2023 18:19:21 +0200 Subject: [PATCH 1/3] fix(types): Use alternative Omit --- packages/dts-test/setupHelpers.test-d.ts | 25 ++++++++++++++++++++ packages/runtime-core/src/apiSetupHelpers.ts | 7 +++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/dts-test/setupHelpers.test-d.ts b/packages/dts-test/setupHelpers.test-d.ts index feb4085dea0..45a90ed6bca 100644 --- a/packages/dts-test/setupHelpers.test-d.ts +++ b/packages/dts-test/setupHelpers.test-d.ts @@ -100,6 +100,31 @@ describe('defineProps w/ union type declaration + withDefaults', () => { ) }) +describe('defineProps w/ generic discriminate union + withDefaults', () => { + interface B { + b?: string + } + interface S extends B { + mode: 'single' + v: T + } + interface M extends B { + mode: 'multiple' + v: T[] + } + type Props = S | M + const props = withDefaults(defineProps(), { + b: 'b' + }) + + if (props.mode === 'single') { + expectType(props.v) + } + if (props.mode === 'multiple') { + expectType(props.v) + } +}) + describe('defineProps w/ generic type declaration + withDefaults', = | ((props: P) => T & {}) | (T extends NativeType ? T : never) +// https://github.com/vuejs/core/issues/9335 +type OmitKeepDiscriminatedUnion = T extends any + ? Pick> + : never + type PropsWithDefaults< T, Defaults extends InferDefaults, BKeys extends keyof T -> = Omit & { +> = OmitKeepDiscriminatedUnion & { [K in keyof Defaults]-?: K extends keyof T ? Defaults[K] extends undefined ? T[K] From 2fe82278ed878d080c11d077c4926fea20bfbb72 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 2 Aug 2024 11:42:50 +0800 Subject: [PATCH 2/3] Update apiSetupHelpers.ts --- packages/runtime-core/src/apiSetupHelpers.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/runtime-core/src/apiSetupHelpers.ts b/packages/runtime-core/src/apiSetupHelpers.ts index fcb9bc8d3b2..39d8edbcc20 100644 --- a/packages/runtime-core/src/apiSetupHelpers.ts +++ b/packages/runtime-core/src/apiSetupHelpers.ts @@ -298,11 +298,6 @@ type InferDefault = | ((props: P) => T & {}) | (T extends NativeType ? T : never) -// https://github.com/vuejs/core/issues/9335 -type OmitKeepDiscriminatedUnion = T extends any - ? Pick> - : never - type PropsWithDefaults< T, Defaults extends InferDefaults, From 0617fe87c008d1f8c5ad4d5373b37d63717c3061 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Fri, 2 Aug 2024 03:43:35 +0000 Subject: [PATCH 3/3] [autofix.ci] apply automated fixes --- packages/dts-test/setupHelpers.test-d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/dts-test/setupHelpers.test-d.ts b/packages/dts-test/setupHelpers.test-d.ts index d6eea8e923f..729f9b97d05 100644 --- a/packages/dts-test/setupHelpers.test-d.ts +++ b/packages/dts-test/setupHelpers.test-d.ts @@ -151,7 +151,7 @@ describe('defineProps w/ generic discriminate union + withDefaults', () => { } type Props = S | M const props = withDefaults(defineProps(), { - b: 'b' + b: 'b', }) if (props.mode === 'single') {