fix(sfc/types): allow use default factory for primitive types in withDefaults (#5939)

fix #5938
This commit is contained in:
Alex Kozack
2022-05-23 03:28:39 +03:00
committed by GitHub
parent dddbd96dfe
commit b5462822d6
2 changed files with 8 additions and 3 deletions

View File

@@ -28,12 +28,14 @@ describe('defineProps w/ type declaration + withDefaults', () => {
obj?: { x: number }
fn?: (e: string) => void
x?: string
genStr?: string
}>(),
{
number: 123,
arr: () => [],
obj: () => ({ x: 123 }),
fn: () => {}
fn: () => {},
genStr: () => ''
}
)
@@ -43,6 +45,7 @@ describe('defineProps w/ type declaration + withDefaults', () => {
res.fn('hi')
// @ts-expect-error
res.x.slice()
res.genStr.slice()
})
describe('defineProps w/ union type declaration + withDefaults', () => {
@@ -51,11 +54,13 @@ describe('defineProps w/ union type declaration + withDefaults', () => {
union1?: number | number[] | { x: number }
union2?: number | number[] | { x: number }
union3?: number | number[] | { x: number }
union4?: number | number[] | { x: number }
}>(),
{
union1: 123,
union2: () => [123],
union3: () => ({ x: 123 })
union3: () => ({ x: 123 }),
union4: () => 123,
}
)
})