Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow use default factory for primitive types #5939

Merged
merged 2 commits into from May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/runtime-core/src/apiSetupHelpers.ts
Expand Up @@ -139,7 +139,7 @@ type InferDefault<P, T> = T extends
| boolean
| symbol
| Function
? T
? T | ((props: P) => T)
: (props: P) => T

type PropsWithDefaults<Base, Defaults> = Base & {
Expand Down
9 changes: 7 additions & 2 deletions test-dts/setupHelpers.test-d.ts
Expand Up @@ -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: () => ''
}
)

Expand All @@ -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', () => {
Expand All @@ -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,
}
)
})
Expand Down