From 4810f1489fd3b311eac0265e8f2607fd0cbcbfb4 Mon Sep 17 00:00:00 2001 From: Yang Mingshan Date: Tue, 2 Sep 2025 17:13:08 +0800 Subject: [PATCH] chore(types): compatible with TS 5.8 (#12973) --- packages-private/dts-test/scheduler.test-d.ts | 31 +++++++++++++++++++ packages/reactivity/src/ref.ts | 2 +- packages/runtime-core/src/scheduler.ts | 11 +++++-- 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 packages-private/dts-test/scheduler.test-d.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 index 0000000000..26702432bf --- /dev/null +++ b/packages-private/dts-test/scheduler.test-d.ts @@ -0,0 +1,31 @@ +import { nextTick } from 'vue' +import { describe, expectType } from './utils' + +describe('nextTick', async () => { + expectType>(nextTick()) + expectType>(nextTick(() => 'foo')) + expectType>(nextTick(() => Promise.resolve('foo'))) + expectType>( + nextTick(() => Promise.resolve(Promise.resolve('foo'))), + ) + + expectType(await nextTick()) + expectType(await nextTick(() => 'foo')) + expectType(await nextTick(() => Promise.resolve('foo'))) + expectType( + await nextTick(() => Promise.resolve(Promise.resolve('foo'))), + ) + + nextTick().then(value => { + expectType(value) + }) + nextTick(() => 'foo').then(value => { + expectType(value) + }) + nextTick(() => Promise.resolve('foo')).then(value => { + expectType(value) + }) + nextTick(() => Promise.resolve(Promise.resolve('foo'))).then(value => { + expectType(value) + }) +}) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 59b713dd86..024629701d 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -275,7 +275,7 @@ export function proxyRefs( objectWithRefs: T, ): ShallowUnwrapRef { return isReactive(objectWithRefs) - ? objectWithRefs + ? (objectWithRefs as ShallowUnwrapRef) : new Proxy(objectWithRefs, shallowUnwrapHandlers) } diff --git a/packages/runtime-core/src/scheduler.ts b/packages/runtime-core/src/scheduler.ts index b40c31d395..af6752078a 100644 --- a/packages/runtime-core/src/scheduler.ts +++ b/packages/runtime-core/src/scheduler.ts @@ -53,10 +53,15 @@ let currentFlushPromise: Promise | null = null const RECURSION_LIMIT = 100 type CountMap = Map -export function nextTick( +export function nextTick(): Promise +export function nextTick( this: T, - fn?: (this: T) => R, -): Promise> { + fn: (this: T) => R | Promise, +): Promise +export function nextTick( + this: T, + fn?: (this: T) => R | Promise, +): Promise { const p = currentFlushPromise || resolvedPromise return fn ? p.then(this ? fn.bind(this) : fn) : p } -- 2.47.3