Skip to content

fix(types): type Options API computed arguments (fix #13103) - #15220

Open
ifer47 wants to merge 2 commits into
vuejs:mainfrom
ifer47:agent/fix-options-computed-previous-type
Open

fix(types): type Options API computed arguments (fix #13103)#15220
ifer47 wants to merge 2 commits into
vuejs:mainfrom
ifer47:agent/fix-options-computed-previous-type

Conversation

@ifer47

@ifer47 ifer47 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

What changed

  • add Options API-specific computed getter types that model the runtime arguments as (componentInstance, previousValue)
  • use that getter shape for both shorthand and writable computed options
  • export the component getter and writable-option types alongside ComputedOptions
  • add dts coverage that verifies contextual inference for the component instance, previous value, and writable setter without widening to any

Why

Options API computed getters are bound with the public component instance as their first argument before reactivity supplies the previous value. The existing ComputedOptions type reused the Composition API ComputedGetter, so it incorrectly described the previous value as the first argument.

Fixes #13103.

How tested

  • tsc -p tsconfig.build.json --noCheck
  • rollup -c rollup.dts.config.js
  • tsc -p packages-private/dts-built-test/tsconfig.json
  • tsc -p packages-private/dts-test/tsconfig.test.json
  • ESLint on all three changed files
  • Prettier 3.9.6 check on all three changed files
  • git diff --check
  • GitHub CI: lint/dts, Linux and Windows unit tests, release, size, and deployment checks pass on the current head

The focused runtime test could not start locally because the shared dependency snapshot does not contain @vitest/browser-playwright. A full source tsc --incremental --noEmit likewise reaches an unrelated existing dependency mismatch where vitest/browser does not export cdp. 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

  • Risk: low; this is a type-only change, the two new exports are additive, and zero-argument computed getters remain compatible
  • Rollback: revert these commits to restore the previous Options API computed type alias

Notes for reviewers

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Computed property typing

Layer / File(s) Summary
Component computed type contract
packages/runtime-core/src/componentOptions.ts, packages/runtime-core/src/index.ts
ComputedOptions now uses component-specific getter and getter/setter types. Getters accept an optional previous value, setters use ComputedSetter, and the new types are publicly exported.
Computed inference regression coverage
packages-private/dts-test/defineComponent.test-d.tsx
Tests verify component-instance typing, getter return types, previous value types, and writable setter argument types.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the Options API computed argument type fix and references the related issue.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@15220
npm i https://pkg.pr.new/@vue/compiler-core@15220
yarn add https://pkg.pr.new/@vue/compiler-core@15220.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@15220
npm i https://pkg.pr.new/@vue/compiler-dom@15220
yarn add https://pkg.pr.new/@vue/compiler-dom@15220.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@15220
npm i https://pkg.pr.new/@vue/compiler-sfc@15220
yarn add https://pkg.pr.new/@vue/compiler-sfc@15220.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@15220
npm i https://pkg.pr.new/@vue/compiler-ssr@15220
yarn add https://pkg.pr.new/@vue/compiler-ssr@15220.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@15220
npm i https://pkg.pr.new/@vue/reactivity@15220
yarn add https://pkg.pr.new/@vue/reactivity@15220.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@15220
npm i https://pkg.pr.new/@vue/runtime-core@15220
yarn add https://pkg.pr.new/@vue/runtime-core@15220.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@15220
npm i https://pkg.pr.new/@vue/runtime-dom@15220
yarn add https://pkg.pr.new/@vue/runtime-dom@15220.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@15220
npm i https://pkg.pr.new/@vue/server-renderer@15220
yarn add https://pkg.pr.new/@vue/server-renderer@15220.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@15220
npm i https://pkg.pr.new/@vue/shared@15220
yarn add https://pkg.pr.new/@vue/shared@15220.tgz

vue

pnpm add https://pkg.pr.new/vue@15220
npm i https://pkg.pr.new/vue@15220
yarn add https://pkg.pr.new/vue@15220.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@15220
npm i https://pkg.pr.new/@vue/compat@15220
yarn add https://pkg.pr.new/@vue/compat@15220.tgz

commit: 91a1a17

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 108 kB 40.7 kB 36.5 kB
vue.global.prod.js 167 kB 60.9 kB 54.2 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 49.7 kB 19.3 kB 17.7 kB
createApp 57.8 kB 22.3 kB 20.4 kB
createSSRApp 62.5 kB 24.3 kB 22.1 kB
defineCustomElement 64.1 kB 24.3 kB 22.1 kB
overall 72.1 kB 27.5 kB 25.1 kB

@ifer47
ifer47 marked this pull request as ready for review August 7, 2026 01:30

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages-private/dts-test/defineComponent.test-d.tsx (1)

513-536: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Strengthen the regression test’s type assertions.

Lines 516, 523, and 529 explicitly declare the expected types. The expectType<ComputedOptions>(computed) assertion is also tautological because computed is already declared as ComputedOptions. The test can pass if the callback types are widened to any.

Construct the shorthand and writable cases with ComponentComputedGetter<number> and ComponentComputedOptions<number>, then assert the unannotated previous and setter parameters. Also add non-any checks 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

📥 Commits

Reviewing files that changed from the base of the PR and between d2c458b and d2f5cd0.

📒 Files selected for processing (2)
  • packages-private/dts-test/defineComponent.test-d.tsx
  • packages/runtime-core/src/componentOptions.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Computed previous value in options API is component instance

2 participants