mirror of https://github.com/vuejs/core.git
Merge 1a7010468c
into 56be3dd4db
This commit is contained in:
commit
8ec04f73a5
|
@ -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)
|
||||
})
|
||||
})
|
|
@ -263,7 +263,7 @@ export function processFor(
|
|||
dir: DirectiveNode,
|
||||
context: TransformContext,
|
||||
processCodegen?: (forNode: ForNode) => (() => void) | undefined,
|
||||
) {
|
||||
): (() => void) | undefined {
|
||||
if (!dir.exp) {
|
||||
context.onError(
|
||||
createCompilerError(ErrorCodes.X_V_FOR_NO_EXPRESSION, dir.loc),
|
||||
|
|
|
@ -114,7 +114,7 @@ export function processDefineModel(
|
|||
return true
|
||||
}
|
||||
|
||||
export function genModelProps(ctx: ScriptCompileContext) {
|
||||
export function genModelProps(ctx: ScriptCompileContext): string | undefined {
|
||||
if (!ctx.hasDefineModelCall) return
|
||||
|
||||
const isProd = !!ctx.options.isProd
|
||||
|
|
|
@ -275,7 +275,7 @@ export function proxyRefs<T extends object>(
|
|||
objectWithRefs: T,
|
||||
): ShallowUnwrapRef<T> {
|
||||
return isReactive(objectWithRefs)
|
||||
? objectWithRefs
|
||||
? (objectWithRefs as any)
|
||||
: new Proxy(objectWithRefs, shallowUnwrapHandlers)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue