Skip to content

Commit

Permalink
test: update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Oct 4, 2024
1 parent d09f791 commit e88722a
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions packages-private/dts-test/setupHelpers.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ describe('defineProps w/ type declaration + withDefaults', <T extends
bool?: boolean
boolAndUndefined: boolean | undefined
foo?: T
u:
| { type: 'button'; buttonType?: 'submit' }
| { type: 'link'; href: string }
}>(),
{
number: 123,
Expand Down Expand Up @@ -91,13 +88,6 @@ describe('defineProps w/ type declaration + withDefaults', <T extends

expectType<boolean>(res.bool)
expectType<boolean>(res.boolAndUndefined)

if (res.u.type === 'button') {
expectType<'submit' | undefined>(res.u.buttonType)
}
if (res.u.type === 'link') {
expectType<string>(res.u.href)
}
})

describe('defineProps w/ union type declaration + withDefaults', () => {
Expand Down Expand Up @@ -250,6 +240,23 @@ describe('withDefaults w/ defineProp type is different from the defaults type',
res1.value
})

describe('withDefaults w/ defineProp discriminate union type', () => {
const props = withDefaults(
defineProps<
{ type: 'button'; buttonType?: 'submit' } | { type: 'link'; href: string }
>(),
{
type: 'button',
},
)
if (props.type === 'button') {
expectType<'submit' | undefined>(props.buttonType)
}
if (props.type === 'link') {
expectType<string>(props.href)
}
})

describe('defineProps w/ runtime declaration', () => {
// runtime declaration
const props = defineProps({
Expand Down

0 comments on commit e88722a

Please sign in to comment.