]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(types): add test for generic discriminated unions in props (#9336)
authorDavid Matter <davidmatter@users.noreply.github.com>
Fri, 2 Aug 2024 03:45:23 +0000 (05:45 +0200)
committerGitHub <noreply@github.com>
Fri, 2 Aug 2024 03:45:23 +0000 (11:45 +0800)
packages/dts-test/setupHelpers.test-d.ts

index 883ebe6b254ff86a4176b5ce3cc093b829aa6f66..729f9b97d05f08381a22b8d73543e818c4114637 100644 (file)
@@ -137,6 +137,31 @@ describe('defineProps w/ object union + withDefaults', () => {
   >(props)
 })
 
+describe('defineProps w/ generic discriminate union + withDefaults', () => {
+  interface B {
+    b?: string
+  }
+  interface S<T> extends B {
+    mode: 'single'
+    v: T
+  }
+  interface M<T> extends B {
+    mode: 'multiple'
+    v: T[]
+  }
+  type Props = S<string> | M<string>
+  const props = withDefaults(defineProps<Props>(), {
+    b: 'b',
+  })
+
+  if (props.mode === 'single') {
+    expectType<string>(props.v)
+  }
+  if (props.mode === 'multiple') {
+    expectType<string[]>(props.v)
+  }
+})
+
 describe('defineProps w/ generic type declaration + withDefaults', <T extends
   number, TA extends {
   a: string