types(defineProps): avoid never props becoming boolean flags
close #14056
Summary by CodeRabbit
-
Tests
- Added test coverage verifying type behavior when a prop is declared as
never, ensuring regressions are caught.
- Added test coverage verifying type behavior when a prop is declared as
-
Bug Fixes
- Improved TypeScript inference for optional boolean props used with
defineProps, providing stricter and more accurate editor hints and fewer incorrect type widenings.
- Improved TypeScript inference for optional boolean props used with
Walkthrough
Refines a conditional type used to detect boolean-like prop keys and adds a type test ensuring props declared as never are handled correctly by defineProps.
Changes
| Cohort / File(s) | Change Summary |
|---|---|
Test additions packages-private/dts-test/setupHelpers.test-d.ts |
Adds a new test block "defineProps w/ never prop" asserting foo?: never yields `never |
Type narrowing packages/runtime-core/src/apiSetupHelpers.ts |
Changes BooleanKey<T> conditional to further check `T[K] extends boolean |
Sequence Diagram(s)
sequenceDiagram
participant Dev as defineProps call site
participant BooleanKey as BooleanKey<T>
participant TS as TypeScript resolver
Note over Dev,TS: Type selection for each prop key
Dev->>BooleanKey: provide prop type T[K]
BooleanKey->>TS: evaluate "T[K] extends boolean | undefined?"
TS-->>BooleanKey: yes/no
alt matches boolean|undefined
BooleanKey->>TS: evaluate "T[K] extends never | undefined?"
TS-->>BooleanKey: yes -> exclude key
TS-->>BooleanKey: no -> include key
else does not match
BooleanKey-->>Dev: exclude key
end
Estimated code review effort
π― 3 (Moderate) | β±οΈ ~20 minutes
- Key areas for attention:
- Correctness of the nested conditional type in
BooleanKey<T>(verify behavior withnever, optional, and unions likeboolean | undefined/boolean | null) - The new test covers the reported edge case; consider additional tests for required booleans and boolean unions
- Confirm no unintended regressions in other type branches that rely on
BooleanKey
- Correctness of the nested conditional type in
Suggested reviewers
- KazariEX
- johnsoncodehk
Poem
π° A hop of types beneath the moonlit test,
Never hid from props β now checked and dressed.
Boolean keys pruned clean with gentle cheer,
The rabbit stamps approval β types are clear!
Pre-merge checks and finishing touches
β Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | β Passed | Check skipped - CodeRabbitβs high-level summary is enabled. |
| Title check | β Passed | The title clearly describes the main change: fixing a typing issue where never props incorrectly become boolean flags in defineProps. |
| Linked Issues check | β Passed | The PR addresses the core issue (#14056) by refining the BooleanKey type to exclude never props from being treated as boolean flags, which directly resolves the reported typing problem. |
| Out of Scope Changes check | β Passed | All changes are directly scoped to fixing the reported issue: a type refinement in apiSetupHelpers.ts and a corresponding test in the test file. |
| Docstring Coverage | β Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
β¨ Finishing touches
- [ ] π Generate docstrings
π§ͺ Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
- [ ] Commit unit tests in branch
edison/fix/14056
π Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π₯ Commits
Reviewing files that changed from the base of the PR and between 06008628a2348f2825d6231cbe73ea18011bc967 and 6079bdbf0ca036e21c642bc8b22d080df9a7c60e.
π Files selected for processing (1)
packages/runtime-core/src/apiSetupHelpers.ts(1 hunks)
π§ Files skipped from review as they are similar to previous changes (1)
- packages/runtime-core/src/apiSetupHelpers.ts
β° 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). (3)
- GitHub Check: Redirect rules
- GitHub Check: Header rules
- GitHub Check: Pages changed
Comment @coderabbitai help to get the list of available commands and usage tips.
Size Report
Bundles
| File | Size | Gzip | Brotli |
|---|---|---|---|
| runtime-dom.global.prod.js | 103 kB | 38.9 kB | 35 kB |
| vue.global.prod.js | 161 kB | 58.8 kB | 52.4 kB |
Usages
| Name | Size | Gzip | Brotli |
|---|---|---|---|
| createApp (CAPI only) | 46.9 kB | 18.3 kB | 16.8 kB |
| createApp | 55 kB | 21.4 kB | 19.6 kB |
| createSSRApp | 59.3 kB | 23.1 kB | 21.1 kB |
| defineCustomElement | 60.6 kB | 23.1 kB | 21.1 kB |
| overall | 69.3 kB | 26.6 kB | 24.3 kB |
@vue/compiler-core
npm i https://pkg.pr.new/@vue/compiler-core@14059
@vue/compiler-dom
npm i https://pkg.pr.new/@vue/compiler-dom@14059
@vue/compiler-sfc
npm i https://pkg.pr.new/@vue/compiler-sfc@14059
@vue/compiler-ssr
npm i https://pkg.pr.new/@vue/compiler-ssr@14059
@vue/reactivity
npm i https://pkg.pr.new/@vue/reactivity@14059
@vue/runtime-core
npm i https://pkg.pr.new/@vue/runtime-core@14059
@vue/runtime-dom
npm i https://pkg.pr.new/@vue/runtime-dom@14059
@vue/server-renderer
npm i https://pkg.pr.new/@vue/server-renderer@14059
@vue/shared
npm i https://pkg.pr.new/@vue/shared@14059
vue
npm i https://pkg.pr.new/vue@14059
@vue/compat
npm i https://pkg.pr.new/@vue/compat@14059
commit: 6079bdb
/ecosystem-ci run
π Ran ecosystem CI: Open
| suite | result | latest scheduled |
|---|---|---|
| nuxt | :white_check_mark: success | :white_check_mark: success |
| quasar | :white_check_mark: success | :white_check_mark: success |
| pinia | :white_check_mark: success | :white_check_mark: success |
| test-utils | :white_check_mark: success | :white_check_mark: success |
| radix-vue | :white_check_mark: success | :white_check_mark: success |
| router | :white_check_mark: success | :white_check_mark: success |
| primevue | :white_check_mark: success | :white_check_mark: success |
| language-tools | :white_check_mark: success | :white_check_mark: success |
| vue-simple-compiler | :white_check_mark: success | :white_check_mark: success |
| vuetify | :white_check_mark: success | :white_check_mark: success |
| vue-i18n | :x: failure | :x: failure |
| vant | :white_check_mark: success | :x: failure |
| vueuse | :white_check_mark: success | :x: failure |
| vitepress | :white_check_mark: success | :white_check_mark: success |
| vue-macros | :white_check_mark: success | :white_check_mark: success |
| vite-plugin-vue | :white_check_mark: success | :white_check_mark: success |