Skip to content

Commit 4810f14

Browse files
authored
chore(types): compatible with TS 5.8 (#12973)
1 parent 7171def commit 4810f14

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { nextTick } from 'vue'
2+
import { describe, expectType } from './utils'
3+
4+
describe('nextTick', async () => {
5+
expectType<Promise<void>>(nextTick())
6+
expectType<Promise<string>>(nextTick(() => 'foo'))
7+
expectType<Promise<string>>(nextTick(() => Promise.resolve('foo')))
8+
expectType<Promise<string>>(
9+
nextTick(() => Promise.resolve(Promise.resolve('foo'))),
10+
)
11+
12+
expectType<void>(await nextTick())
13+
expectType<string>(await nextTick(() => 'foo'))
14+
expectType<string>(await nextTick(() => Promise.resolve('foo')))
15+
expectType<string>(
16+
await nextTick(() => Promise.resolve(Promise.resolve('foo'))),
17+
)
18+
19+
nextTick().then(value => {
20+
expectType<void>(value)
21+
})
22+
nextTick(() => 'foo').then(value => {
23+
expectType<string>(value)
24+
})
25+
nextTick(() => Promise.resolve('foo')).then(value => {
26+
expectType<string>(value)
27+
})
28+
nextTick(() => Promise.resolve(Promise.resolve('foo'))).then(value => {
29+
expectType<string>(value)
30+
})
31+
})

packages/reactivity/src/ref.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export function proxyRefs<T extends object>(
275275
objectWithRefs: T,
276276
): ShallowUnwrapRef<T> {
277277
return isReactive(objectWithRefs)
278-
? objectWithRefs
278+
? (objectWithRefs as ShallowUnwrapRef<T>)
279279
: new Proxy(objectWithRefs, shallowUnwrapHandlers)
280280
}
281281

packages/runtime-core/src/scheduler.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,15 @@ let currentFlushPromise: Promise<void> | null = null
5353
const RECURSION_LIMIT = 100
5454
type CountMap = Map<SchedulerJob, number>
5555

56-
export function nextTick<T = void, R = void>(
56+
export function nextTick(): Promise<void>
57+
export function nextTick<T, R>(
5758
this: T,
58-
fn?: (this: T) => R,
59-
): Promise<Awaited<R>> {
59+
fn: (this: T) => R | Promise<R>,
60+
): Promise<R>
61+
export function nextTick<T, R>(
62+
this: T,
63+
fn?: (this: T) => R | Promise<R>,
64+
): Promise<void | R> {
6065
const p = currentFlushPromise || resolvedPromise
6166
return fn ? p.then(this ? fn.bind(this) : fn) : p
6267
}

0 commit comments

Comments
 (0)