Skip to content

Conversation

alex-snezhko
Copy link
Contributor

@alex-snezhko alex-snezhko commented Sep 1, 2025

close #13807

I effectively reused the type signatures from apiWatch.ts with an additional overload for WatchEffect as the first argument

Summary by CodeRabbit

  • New Features
    • Exposed the MultiWatchSources type in the public API, making it directly available to TypeScript users.
  • Refactor
    • Consolidated MultiWatchSources to source from the reactivity types, removing local aliases and aligning type exports across packages.
  • Chores
    • Adjusted internal typings in watch-related logic to rely on the centralized type and simplified callback typing.
  • Notes
    • No runtime behavior changes; impact is limited to TypeScript type availability and consistency.

Copy link

coderabbitai bot commented Sep 1, 2025

Walkthrough

Re-exports the MultiWatchSources type from @vue/reactivity, removes the local alias in runtime-core, and updates exports accordingly. In doWatch, the callback passed to baseWatch is cast to any. No runtime behavior changes are introduced; updates are limited to type exports and internal typing.

Changes

Cohort / File(s) Summary
Reactivity public API exports
packages/reactivity/src/index.ts
Re-exported type MultiWatchSources from ./watch.
Runtime-core watch typings and implementation
packages/runtime-core/src/apiWatch.ts
Imported MultiWatchSources type from @vue/reactivity, removed local exported alias, updated overloads to use imported type, and cast callback to any in doWatch.
Runtime-core public API exports
packages/runtime-core/src/index.ts
Re-exported MultiWatchSources from @vue/reactivity; removed MultiWatchSources re-export from ./apiWatch.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
Add TS generics to watch() in @vue/reactivity so new/old values aren’t any (#13807) No changes to watch() generics in packages/reactivity/src/watch.ts; only type re-exports and internal typing adjustments elsewhere.

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Cast watcher callback to any in doWatch (packages/runtime-core/src/apiWatch.ts) Alters internal typing and not required to enable generics in @vue/reactivity watch().
Re-export MultiWatchSources from reactivity (packages/reactivity/src/index.ts) Adjusts public type surface but does not implement generics for watch().
Move MultiWatchSources export source (packages/runtime-core/src/index.ts) Public export routing change unrelated to watch() generics in @vue/reactivity.

Poem

I twitch my ears at types that flow,
From roots of reactivity, they grow.
We shuffled names, a tidy hop—
No runtime carrots yet to chop.
Still, I thump in hopeful glee:
Next patch, generics set us free! 🥕🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented Sep 1, 2025

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB 38.4 kB 34.6 kB
vue.global.prod.js 159 kB 58.5 kB 52.1 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.5 kB 18.2 kB 16.7 kB
createApp 54.5 kB 21.2 kB 19.4 kB
createSSRApp 58.7 kB 22.9 kB 20.9 kB
defineCustomElement 59.5 kB 22.8 kB 20.8 kB
overall 68.5 kB 26.4 kB 24 kB

Copy link

pkg-pr-new bot commented Sep 1, 2025

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@13840

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@13840

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@13840

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@13840

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@13840

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@13840

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@13840

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@13840

@vue/shared

npm i https://pkg.pr.new/@vue/shared@13840

vue

npm i https://pkg.pr.new/vue@13840

@vue/compat

npm i https://pkg.pr.new/@vue/compat@13840

commit: 308673a

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/reactivity/src/watch.ts (1)

327-331: Avoid ts-expect-error by casting cb once.
Keeps types clean and prevents “expect error not found” drift across TS versions.

Apply:

-          call
-            ? call(cb!, WatchErrorCodes.WATCH_CALLBACK, args)
-            : // @ts-expect-error
-              cb!(...args)
+          const cbAny = cb as any
+          call ? call(cbAny, WatchErrorCodes.WATCH_CALLBACK, args) : cbAny(...args)
packages/runtime-core/src/apiWatch.ts (1)

225-225: Casting cb as any when calling baseWatch is acceptable here.
Prevents complex generic explosion while preserving typed overloads at the API boundary.

Consider a short comment explaining why the cast is necessary to help future maintainers.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d11cdd4 and 308673a.

📒 Files selected for processing (4)
  • packages/reactivity/src/index.ts (1 hunks)
  • packages/reactivity/src/watch.ts (2 hunks)
  • packages/runtime-core/src/apiWatch.ts (2 hunks)
  • packages/runtime-core/src/index.ts (1 hunks)
🔥 Files not summarized due to errors (1)
  • packages/reactivity/src/watch.ts: Error: Server error: no LLM provider could handle the message
🧰 Additional context used
🧬 Code graph analysis (1)
packages/reactivity/src/watch.ts (2)
packages/reactivity/src/index.ts (8)
  • MultiWatchSources (89-89)
  • WatchSource (95-95)
  • watch (84-84)
  • WatchEffect (94-94)
  • WatchOptions (90-90)
  • WatchHandle (93-93)
  • WatchCallback (96-96)
  • ReactiveMarker (41-41)
packages/runtime-core/src/apiWatch.ts (6)
  • WatchSource (30-30)
  • watch (125-138)
  • WatchEffect (29-29)
  • WatchOptions (49-53)
  • WatchHandle (27-27)
  • WatchCallback (31-31)
⏰ 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
🔇 Additional comments (6)
packages/reactivity/src/watch.ts (3)

24-24: Importing ReactiveMarker/isReactive/isShallow is correct and used below.
No issues; aligns with overload discrimination and runtime checks.


120-131: Type utilities mirror runtime-core and enable generic oldValue typing.
MaybeUndefined, MultiWatchSources, and MapSources look consistent and should fix the generic inference gap.


132-177: Overload set restores full generic parity with runtime-core.
The added WatchEffect-first overload and the tuple/array/object sources overloads look right and unblock typed new/old values.

packages/reactivity/src/index.ts (1)

89-89: Re-exporting MultiWatchSources from watch is the right public surface.
Keeps a single source of truth for the alias and simplifies runtime-core usage.

packages/runtime-core/src/apiWatch.ts (1)

4-4: Import MultiWatchSources from @vue/reactivity.
Good consolidation; removes local alias duplication.

packages/runtime-core/src/index.ts (1)

227-228: Type re-export for MultiWatchSources from reactivity looks good.
Ensures stable public typing for consumers importing from 'vue'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[@vue/reactivity] watch() doesn't accept TS generics
1 participant