Skip to content

test: strict type assertion - #15107

Open
KazariAI wants to merge 4 commits into
vuejs:mainfrom
KazariAI:test/strict-type-assertion
Open

test: strict type assertion#15107
KazariAI wants to merge 4 commits into
vuejs:mainfrom
KazariAI:test/strict-type-assertion

Conversation

@KazariAI

@KazariAI KazariAI commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • make expectType require exact type equality
  • migrate existing type assertions and use expectAssignable where assignability is intentional
  • remove redundant negative assertions covered by exact checks

This pull request was created with assistance from a code agent.

Summary by CodeRabbit

  • Tests
    • Improved compile-time TypeScript validation across directives, components, reactivity, refs, watchers, JSX/TSX, custom elements, scheduler, and compiler helpers.
    • Updated type-test assertions to a stricter equality/assignability style (including refined optionality, event/handler, model, slot, and callback parameter expectations).
    • Enhanced the shared expectType helper to enforce type equality, with additional dts test coverage for failure cases.
    • No runtime behavior or public API changes.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The pull request upgrades the declaration-test expectType helper to compare actual and expected types, adds expectAssignable, and migrates Vue type assertions across component, reactivity, macro, watcher, JSX, and API tests.

Changes

Declaration test assertion migration

Layer / File(s) Summary
Assertion helper and basic API checks
packages-private/dts-test/utils.d.ts, packages-private/dts-test/*.test-d.ts
expectType now performs mutual-assignability equality checks, while API assertions use value-based expected-type witnesses and explicit assignability checks.
Component, custom-element, and JSX type tests
packages-private/dts-test/component*.test-d*, packages-private/dts-test/defineComponent.test-d.tsx, packages-private/dts-test/defineCustomElement.test-d.ts, packages-private/dts-test/tsx.test-d.tsx
Component props, instances, emits, slots, directives, JSX results, and custom-element constructors use revised exact-type and assignability assertions.
Reactivity, refs, macros, props, and watchers
packages-private/dts-test/reactivity.test-d.ts, packages-private/dts-test/ref.test-d.ts, packages-private/dts-test/setupHelpers.test-d.ts, packages-private/dts-test/watch.test-d.ts
Reactivity, ref, macro, prop, and watcher tests express exact types, assignability, optional values, unwrapping, and model behavior with the revised helpers.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • vuejs/core#15097: Both changes update defineModel type-inference assertions in setupHelpers.test-d.ts.

Suggested labels: scope: types

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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 matches the main change: tightening type assertions in tests to require stricter exactness.
✨ 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.

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

Actionable comments posted: 1

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

Inline comments:
In `@packages-private/dts-test/component.test-d.ts`:
- Around line 201-204: Replace the boxed Number-based expectAssignable
assertions in the rawBindings checks and the corresponding assertion groups at
the referenced locations with exact expectType assertions using lowercase number
and Ref<number> types. Preserve the optional union for setupD as Ref<number> |
undefined, and update all three affected groups consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0d7df7f7-bf52-446b-a355-6e78eb5cc066

📥 Commits

Reviewing files that changed from the base of the PR and between fa2885d and 6b8b9e8.

📒 Files selected for processing (20)
  • packages-private/dts-test/appDirective.test-d.ts
  • packages-private/dts-test/built.test-d.ts
  • packages-private/dts-test/compiler.test-d.ts
  • packages-private/dts-test/component.test-d.ts
  • packages-private/dts-test/componentInstance.test-d.tsx
  • packages-private/dts-test/componentTypeExtensions.test-d.tsx
  • packages-private/dts-test/defineComponent.test-d.tsx
  • packages-private/dts-test/defineCustomElement.test-d.ts
  • packages-private/dts-test/directives.test-d.ts
  • packages-private/dts-test/extractProps.test-d.ts
  • packages-private/dts-test/functionalComponent.test-d.tsx
  • packages-private/dts-test/h.test-d.ts
  • packages-private/dts-test/inject.test-d.ts
  • packages-private/dts-test/reactivity.test-d.ts
  • packages-private/dts-test/ref.test-d.ts
  • packages-private/dts-test/scheduler.test-d.ts
  • packages-private/dts-test/setupHelpers.test-d.ts
  • packages-private/dts-test/tsx.test-d.tsx
  • packages-private/dts-test/utils.d.ts
  • packages-private/dts-test/watch.test-d.ts

Comment thread packages-private/dts-test/component.test-d.ts Outdated
@pkg-pr-new

pkg-pr-new Bot commented Jul 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: a8a0b0f

@github-actions

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 107 kB 40.5 kB 36.3 kB
vue.global.prod.js 166 kB 60.6 kB 53.8 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 49.2 kB 19.1 kB 17.5 kB
createApp 57.3 kB 22.2 kB 20.3 kB
createSSRApp 61.9 kB 24.1 kB 21.9 kB
defineCustomElement 63.5 kB 24.1 kB 22 kB
overall 71.9 kB 27.5 kB 25 kB

@edison1105 edison1105 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The exact-equality helper is a good direction, but this migration currently treats several suspicious existing types as the new contract and removes positive coverage. I verified the full DTS suite at both the PR base and head, then added focused usage checks: mutable models inferred from primitive defaults reject other values, raw-object ComponentInstance results are unsound, and the expectAssignable versions of the generic-ref and local-directive cases pass. Please address the inline issues, restore the removed positive coverage, and add a small sanity test for the helper (1 vs number, any vs number, and readonly vs mutable). It would also be better to retain the documented method-signature defineSlots case unless changing that test scenario is intentional.

Comment thread packages-private/dts-test/setupHelpers.test-d.ts Outdated
Comment thread packages-private/dts-test/componentInstance.test-d.tsx Outdated
Comment thread packages-private/dts-test/ref.test-d.ts Outdated
Comment thread packages-private/dts-test/defineComponent.test-d.tsx
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.

2 participants