]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore(types): compatible with TS 5.8 (#12973)
authorYang Mingshan <y.mingshan3@gmail.com>
Tue, 2 Sep 2025 09:13:08 +0000 (17:13 +0800)
committerGitHub <noreply@github.com>
Tue, 2 Sep 2025 09:13:08 +0000 (17:13 +0800)
packages-private/dts-test/scheduler.test-d.ts [new file with mode: 0644]
packages/reactivity/src/ref.ts
packages/runtime-core/src/scheduler.ts

diff --git a/packages-private/dts-test/scheduler.test-d.ts b/packages-private/dts-test/scheduler.test-d.ts
new file mode 100644 (file)
index 0000000..2670243
--- /dev/null
@@ -0,0 +1,31 @@
+import { nextTick } from 'vue'
+import { describe, expectType } from './utils'
+
+describe('nextTick', async () => {
+  expectType<Promise<void>>(nextTick())
+  expectType<Promise<string>>(nextTick(() => 'foo'))
+  expectType<Promise<string>>(nextTick(() => Promise.resolve('foo')))
+  expectType<Promise<string>>(
+    nextTick(() => Promise.resolve(Promise.resolve('foo'))),
+  )
+
+  expectType<void>(await nextTick())
+  expectType<string>(await nextTick(() => 'foo'))
+  expectType<string>(await nextTick(() => Promise.resolve('foo')))
+  expectType<string>(
+    await nextTick(() => Promise.resolve(Promise.resolve('foo'))),
+  )
+
+  nextTick().then(value => {
+    expectType<void>(value)
+  })
+  nextTick(() => 'foo').then(value => {
+    expectType<string>(value)
+  })
+  nextTick(() => Promise.resolve('foo')).then(value => {
+    expectType<string>(value)
+  })
+  nextTick(() => Promise.resolve(Promise.resolve('foo'))).then(value => {
+    expectType<string>(value)
+  })
+})
index 59b713dd8628e0e1d6a946c018a94a2138ac249d..024629701ddf1130e2ca08af79584e02f3c38de5 100644 (file)
@@ -275,7 +275,7 @@ export function proxyRefs<T extends object>(
   objectWithRefs: T,
 ): ShallowUnwrapRef<T> {
   return isReactive(objectWithRefs)
-    ? objectWithRefs
+    ? (objectWithRefs as ShallowUnwrapRef<T>)
     : new Proxy(objectWithRefs, shallowUnwrapHandlers)
 }
 
index b40c31d395211325bef0dcc965c1189ed8a58e24..af6752078aa399b1a5603371133eee313ef892a5 100644 (file)
@@ -53,10 +53,15 @@ let currentFlushPromise: Promise<void> | null = null
 const RECURSION_LIMIT = 100
 type CountMap = Map<SchedulerJob, number>
 
-export function nextTick<T = void, R = void>(
+export function nextTick(): Promise<void>
+export function nextTick<T, R>(
   this: T,
-  fn?: (this: T) => R,
-): Promise<Awaited<R>> {
+  fn: (this: T) => R | Promise<R>,
+): Promise<R>
+export function nextTick<T, R>(
+  this: T,
+  fn?: (this: T) => R | Promise<R>,
+): Promise<void | R> {
   const p = currentFlushPromise || resolvedPromise
   return fn ? p.then(this ? fn.bind(this) : fn) : p
 }