Skip to content

Conversation

yangmingshan
Copy link
Contributor

@yangmingshan yangmingshan commented Mar 1, 2025

Ref: https://devblogs.microsoft.com/typescript/announcing-typescript-5-8/#granular-checks-for-branches-in-return-expressions

This PR didn't upgrade TypeScript, it only fixed the type errors that arose after the upgrade.

I couldn't find an elegant solution for proxyRefs, so I resorted to using as any 😬

Summary by CodeRabbit

  • New Features

    • Enhanced TypeScript typings for nextTick with new overloads and improved type inference for callbacks, no-arg calls, awaiting, and promise chaining.
  • Refactor

    • Aligned TypeScript return type of proxyRefs for reactive inputs to reflect shallow unwrapping; no runtime behavior change.
  • Tests

    • Added TypeScript declaration tests validating nextTick overloads, awaited usage, and promise chaining to ensure accurate type inference.

Copy link

github-actions bot commented Mar 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.2 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 Mar 1, 2025

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-sfc

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

@vue/compiler-ssr

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: fac379a

@yangmingshan yangmingshan changed the title fix(type): compatible with TS 5.8 types: compatible with TS 5.8 Mar 1, 2025
@@ -113,7 +118,9 @@ export function queueJob(job: SchedulerJob): void {

function queueFlush() {
if (!currentFlushPromise) {
currentFlushPromise = resolvedPromise.then(flushJobs)
currentFlushPromise = resolvedPromise.then(() => {
Copy link
Member

Choose a reason for hiding this comment

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

I tested that revert this change and the change of line 50.
tsc works fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I just thought we can get rid of the type assertion, I can change it back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted.

@yangmingshan
Copy link
Contributor Author

I added some type tests for nextTick

Copy link

coderabbitai bot commented Sep 1, 2025

Walkthrough

Adds TypeScript type test for nextTick, updates nextTick overloads to include no-arg and promise-returning callback variants, and adjusts proxyRefs reactive-branch return type via cast. No runtime logic changes.

Changes

Cohort / File(s) Summary
Scheduler typings
packages/runtime-core/src/scheduler.ts
Adds explicit overloads: nextTick(): Promise<void> and nextTick<T,R>(this:T, fn:(this:T)=>R | Promise<R>): Promise<R>. Implementation signature updated to accept fn?: (this:T)=>R | Promise<R> returning Promise<void | R>. Runtime logic unchanged.
Reactivity proxyRefs typing
packages/reactivity/src/ref.ts
In proxyRefs, when input is reactive, returns objectWithRefs as ShallowUnwrapRef<T> to align TypeScript typing; behavior unchanged.
DTS tests for nextTick
packages-private/dts-test/scheduler.test-d.ts
New tests validating nextTick overloads: no-arg, callback returning value or Promise, awaited usage, and chaining; verifies inferred types with expectType.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • johnsoncodehk
  • sxzz

Poem

Thump-thump go my paws in ticking delight,
New types hop in, neat as the night.
Overloads bloom, promises sing,
Proxy refs don a lighter spring.
Tests nibble edges, snug and quick—
Carrot-shaped checks for nextTick. 🥕🐇

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

@edison1105
Copy link
Member

/ecosystem-ci run

@edison1105 edison1105 changed the title types: compatible with TS 5.8 chore(types): compatible with TS 5.8 Sep 1, 2025
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 (3)
packages/reactivity/src/ref.ts (1)

274-280: Add a brief comment explaining why the cast is required.

Preempt future “cleanup” regressions by documenting that TS 5.8 requires this assertion to make both branches assignable to the declared return type.

Apply:

 export function proxyRefs<T extends object>(
   objectWithRefs: T,
 ): ShallowUnwrapRef<T> {
   return isReactive(objectWithRefs)
-    ? (objectWithRefs as ShallowUnwrapRef<T>)
+    // TS 5.8: granular checks for return branches require the reactive branch
+    // to be explicitly asserted to `ShallowUnwrapRef<T>`.
+    ? (objectWithRefs as ShallowUnwrapRef<T>)
     : new Proxy(objectWithRefs, shallowUnwrapHandlers)
 }
packages-private/dts-test/scheduler.test-d.ts (1)

4-31: Good coverage of overload resolution and Promise flattening.

Consider adding a test that verifies this binding inference for the callback overload.

Suggested addition:

 describe('nextTick', async () => {
+  // `this` binding inference for callback overload
+  const ctx = { foo: 1 }
+  expectType<Promise<number>>(
+    nextTick.call(ctx, function () {
+      expectType<{ foo: number }>(this)
+      return 1
+    }),
+  )
packages/runtime-core/src/scheduler.ts (1)

65-67: Avoid falsy-this edge case in binding.

this ? fn.bind(this) : fn skips binding when this is falsy (e.g., 0), losing the intended context. Calling via .call avoids this.

Apply:

-  return fn ? p.then(this ? fn.bind(this) : fn) : p
+  return fn ? p.then(() => fn.call(this)) : p
📜 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 6327966 and fac379a.

📒 Files selected for processing (3)
  • packages-private/dts-test/scheduler.test-d.ts (1 hunks)
  • packages/reactivity/src/ref.ts (1 hunks)
  • packages/runtime-core/src/scheduler.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/reactivity/src/ref.ts (2)
packages/runtime-core/src/index.ts (1)
  • ShallowUnwrapRef (208-208)
packages/reactivity/src/index.ts (1)
  • ShallowUnwrapRef (19-19)
🔇 Additional comments (2)
packages/reactivity/src/ref.ts (1)

274-280: TS 5.8 return-branch tightening: the cast is appropriate.

The explicit cast on the reactive branch aligns both branches to ShallowUnwrapRef<T> under TS 5.8’s granular return-branch checks. Runtime semantics remain unchanged.

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

56-67: Overloads accurately model nextTick usages.

The no-arg Promise<void> and generic callback overload returning Promise<R> match real call sites and fix TS 5.8 branch-check issues.

@vuejs vuejs deleted a comment from edison1105 Sep 1, 2025
@vue-bot
Copy link
Contributor

vue-bot commented Sep 1, 2025

📝 Ran ecosystem CI: Open

suite result latest scheduled
quasar success success
pinia success success
radix-vue success success
language-tools success success
nuxt success success
primevue success success
router success success
vue-macros failure failure
vuetify success success
vitepress success success
vant success failure
vueuse success success
vite-plugin-vue success success
vue-i18n success success
vue-simple-compiler success success
test-utils success success

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge The PR is ready to be merged. scope: types
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants