Skip to content

Commit

Permalink
test(types): add test for generic discriminated unions in props (#9336)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmatter committed Aug 2, 2024
1 parent 0b8ba63 commit 2a29a71
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/dts-test/setupHelpers.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2a29a71

Please sign in to comment.