Skip to content

Commit 2a29a71

Browse files
authored
test(types): add test for generic discriminated unions in props (#9336)
1 parent 0b8ba63 commit 2a29a71

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

packages/dts-test/setupHelpers.test-d.ts

+25
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,31 @@ describe('defineProps w/ object union + withDefaults', () => {
137137
>(props)
138138
})
139139

140+
describe('defineProps w/ generic discriminate union + withDefaults', () => {
141+
interface B {
142+
b?: string
143+
}
144+
interface S<T> extends B {
145+
mode: 'single'
146+
v: T
147+
}
148+
interface M<T> extends B {
149+
mode: 'multiple'
150+
v: T[]
151+
}
152+
type Props = S<string> | M<string>
153+
const props = withDefaults(defineProps<Props>(), {
154+
b: 'b',
155+
})
156+
157+
if (props.mode === 'single') {
158+
expectType<string>(props.v)
159+
}
160+
if (props.mode === 'multiple') {
161+
expectType<string[]>(props.v)
162+
}
163+
})
164+
140165
describe('defineProps w/ generic type declaration + withDefaults', <T extends
141166
number, TA extends {
142167
a: string

0 commit comments

Comments
 (0)