2
0
Эх сурвалжийг харах

test(types): add test for generic discriminated unions in props (#9336)

David Matter 1 жил өмнө
parent
commit
2a29a71d8a

+ 25 - 0
packages/dts-test/setupHelpers.test-d.ts

@@ -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