-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
types(defineProps): avoid never props becoming boolean flags #14059
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughModifies the Changes
Sequence Diagram(s)sequenceDiagram
participant User as defineProps()
participant BooleanKey
participant TypeCheck as Type Resolver
Note over User,TypeCheck: Old Behavior
User->>BooleanKey: foo?: never
BooleanKey->>TypeCheck: Check [T[K]] extends [boolean | undefined]
TypeCheck-->>BooleanKey: false (doesn't match)
BooleanKey-->>User: Exclude foo
User->>BooleanKey: bar?: boolean
BooleanKey->>TypeCheck: Check [T[K]] extends [boolean | undefined]
TypeCheck-->>BooleanKey: true
BooleanKey-->>User: Include bar (unconditional)
Note over User,TypeCheck: New Behavior
User->>BooleanKey: foo?: never
BooleanKey->>TypeCheck: Check [T[K]] extends [boolean | undefined]
TypeCheck-->>BooleanKey: false
BooleanKey-->>User: Exclude foo ✓
User->>BooleanKey: bar?: boolean
BooleanKey->>TypeCheck: Check [T[K]] extends [boolean | undefined]
TypeCheck-->>BooleanKey: true, then check boolean extends T[K]
TypeCheck-->>BooleanKey: true
BooleanKey-->>User: Include bar ✓
User->>BooleanKey: baz?: boolean | undefined
BooleanKey->>TypeCheck: Check [T[K]] extends [boolean | undefined]
TypeCheck-->>BooleanKey: true, then check boolean extends T[K]
TypeCheck-->>BooleanKey: false (undefined in union blocks extension)
BooleanKey-->>User: Exclude baz ✓
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code graph analysis (1)packages-private/dts-test/setupHelpers.test-d.ts (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🔇 Additional comments (2)
Comment |
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
| type BooleanKey<T, K extends keyof T = keyof T> = K extends any | ||
| ? [T[K]] extends [boolean | undefined] | ||
| ? K | ||
| ? boolean extends T[K] | ||
| ? K | ||
| : never | ||
| : never | ||
| : never |
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.
| type BooleanKey<T, K extends keyof T = keyof T> = K extends any | |
| ? [T[K]] extends [boolean | undefined] | |
| ? K | |
| ? boolean extends T[K] | |
| ? K | |
| : never | |
| : never | |
| : never | |
| type BooleanKey<T, K extends keyof T = keyof T> = K extends any | |
| ? T[K] extends boolean | undefined | |
| ? T[K] extends never | undefined | |
| ? never | |
| : K | |
| : never | |
| : never |
boolean extends T[K] will cause that true or false is not inferred as boolean keys.
close #14056
Summary by CodeRabbit
Tests
neverprop declarations.Bug Fixes
defineProps, ensuring stricter and more accurate TypeScript hints for prop type narrowing.