-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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(runtime-core): return boolean type when use defineProps
to set optional boolean prop
#7116
Changes from all commits
f5af09f
859abae
054f71d
151cc56
df5656f
2631132
8c750a9
bffb1b2
9a9cbdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,16 +13,23 @@ describe('defineProps w/ type declaration', () => { | |
// type declaration | ||
const props = defineProps<{ | ||
foo: string | ||
bool?: boolean | ||
boolAndUndefined: boolean | undefined | ||
}>() | ||
// explicitly declared type should be refined | ||
expectType<string>(props.foo) | ||
// the Boolean absent props will be cast to false | ||
expectType<boolean>(props.bool) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implementation will lead it cannot jump to the declaration by clicking There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll create a new PR with another implementation. |
||
expectType<boolean>(props.boolAndUndefined) | ||
// @ts-expect-error | ||
props.bar | ||
}) | ||
|
||
describe('defineProps w/ type declaration + withDefaults', () => { | ||
const res = withDefaults( | ||
defineProps<{ | ||
bool?: boolean | ||
boolAndUndefined: boolean | undefined | ||
number?: number | ||
arr?: string[] | ||
obj?: { x: number } | ||
|
@@ -33,6 +40,7 @@ describe('defineProps w/ type declaration + withDefaults', () => { | |
z?: string | ||
}>(), | ||
{ | ||
bool: undefined, | ||
number: 123, | ||
arr: () => [], | ||
obj: () => ({ x: 123 }), | ||
|
@@ -53,6 +61,8 @@ describe('defineProps w/ type declaration + withDefaults', () => { | |
// @ts-expect-error | ||
res.y.slice() | ||
|
||
expectType<boolean | undefined>(res.bool) | ||
expectType<boolean | undefined>(res.boolAndUndefined) | ||
expectType<string | undefined>(res.x) | ||
expectType<string | undefined>(res.y) | ||
expectType<string>(res.z) | ||
|
@@ -70,7 +80,7 @@ describe('defineProps w/ union type declaration + withDefaults', () => { | |
union1: 123, | ||
union2: () => [123], | ||
union3: () => ({ x: 123 }), | ||
union4: () => 123, | ||
union4: () => 123 | ||
} | ||
) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider this case