fix(types): type Options API computed arguments (fix #13103) - #15220
fix(types): type Options API computed arguments (fix #13103)#15220ifer47 wants to merge 2 commits into
Conversation
📝 WalkthroughWalkthroughThe PR adds component-specific computed option types with typed previous values and setters. It also adds Options API type-inference tests for read-only and writable computed properties. ChangesComputed property typing
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@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: |
Size ReportBundles
Usages
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages-private/dts-test/defineComponent.test-d.tsx (1)
513-536: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winStrengthen the regression test’s type assertions.
Lines 516, 523, and 529 explicitly declare the expected types. The
expectType<ComputedOptions>(computed)assertion is also tautological becausecomputedis already declared asComputedOptions. The test can pass if the callback types are widened toany.Construct the shorthand and writable cases with
ComponentComputedGetter<number>andComponentComputedOptions<number>, then assert the unannotatedpreviousand setter parameters. Also add non-anychecks for those parameters.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages-private/dts-test/defineComponent.test-d.tsx` around lines 513 - 536, Strengthen the computed inference regression test by removing the explicit callback parameter annotations and tautological ComputedOptions assertion. In the test around the computed shorthand and writable cases, construct the values using ComponentComputedGetter<number> and ComponentComputedOptions<number>, then assert inferred previous and setter parameter types with expectType and add IsAny checks to ensure they are not any.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages-private/dts-test/defineComponent.test-d.tsx`:
- Around line 513-536: Strengthen the computed inference regression test by
removing the explicit callback parameter annotations and tautological
ComputedOptions assertion. In the test around the computed shorthand and
writable cases, construct the values using ComponentComputedGetter<number> and
ComponentComputedOptions<number>, then assert inferred previous and setter
parameter types with expectType and add IsAny checks to ensure they are not any.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 9e66fc64-240d-458b-ac00-50ae5e02380a
📒 Files selected for processing (2)
packages-private/dts-test/defineComponent.test-d.tsxpackages/runtime-core/src/componentOptions.ts
What changed
(componentInstance, previousValue)ComputedOptionsanyWhy
Options API computed getters are bound with the public component instance as their first argument before reactivity supplies the previous value. The existing
ComputedOptionstype reused the Composition APIComputedGetter, so it incorrectly described the previous value as the first argument.Fixes #13103.
How tested
tsc -p tsconfig.build.json --noCheckrollup -c rollup.dts.config.jstsc -p packages-private/dts-built-test/tsconfig.jsontsc -p packages-private/dts-test/tsconfig.test.jsongit diff --checkThe focused runtime test could not start locally because the shared dependency snapshot does not contain
@vitest/browser-playwright. A full sourcetsc --incremental --noEmitlikewise reaches an unrelated existing dependency mismatch wherevitest/browserdoes not exportcdp. The declaration build and both complete dts suites pass locally.The initial GitHub CI run passed e2e. After the type-test-only follow-up, e2e hit an unrelated transition timing failure in
Transition.spec.ts:1706: the expected element still had its enter classes. This PR does not change runtime code, and fork authors cannot rerun upstream jobs, so the failed job needs a maintainer rerun.Risk and rollout
Notes for reviewers
opt.bind(publicThis, publicThis)call.ComponentComputedGetter, Options API computed previous-value wording, file paths, and related commits across open, closed, and merged work. No core PR or commit covers this fix.componentOptions.ts, the computed argument contract, or Computed previous value in options API is component instance #13103. It may touch the same test file but is not an implementation duplicate. The only issue-linked work remains docs(computed): correct parameter in computed example docs#3206, which corrected the documentation example without changing core types.