mirror of https://github.com/vuejs/core.git
test(types): add test for generic discriminated unions in props (#9336)
This commit is contained in:
parent
0b8ba6320e
commit
2a29a71d8a
|
@ -137,6 +137,31 @@ describe('defineProps w/ object union + withDefaults', () => {
|
||||||
>(props)
|
>(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
|
describe('defineProps w/ generic type declaration + withDefaults', <T extends
|
||||||
number, TA extends {
|
number, TA extends {
|
||||||
a: string
|
a: string
|
||||||
|
|
Loading…
Reference in New Issue