UNPKG

@antdv/pro-utils

Version:

@antdv/pro-utils

30 lines (29 loc) 1.99 kB
import type { ShallowUnwrapRef, WatchOptions, WatchSource } from 'vue'; import type { ElementOf, MaybeRefOrGetter } from '../../vueuse/interface'; export interface UntilToMatchOptions { timeout?: number; throwOnTimeout?: boolean; flush?: WatchOptions['flush']; deep?: WatchOptions['deep']; } export interface UntilBaseInstance<T, Not extends boolean = false> { toMatch: (<U extends T = T>(condition: (v: T) => v is U, options?: UntilToMatchOptions) => Not extends true ? Promise<Exclude<T, U>> : Promise<U>) & ((condition: (v: T) => boolean, options?: UntilToMatchOptions) => Promise<T>); changed: (options?: UntilToMatchOptions) => Promise<T>; changedTimes: (n?: number, options?: UntilToMatchOptions) => Promise<T>; } type Falsy = false | void | null | undefined | 0 | 0n | ''; export interface UntilValueInstance<T, Not extends boolean = false> extends UntilBaseInstance<T, Not> { readonly not: UntilValueInstance<T, Not extends true ? false : true>; toBe: <P = T>(value: MaybeRefOrGetter<P>, options?: UntilToMatchOptions) => Not extends true ? Promise<T> : Promise<P>; toBeTruthy: (options?: UntilToMatchOptions) => Not extends true ? Promise<T & Falsy> : Promise<Exclude<T, Falsy>>; toBeNull: (options?: UntilToMatchOptions) => Not extends true ? Promise<Exclude<T, null>> : Promise<null>; toBeUndefined: (options?: UntilToMatchOptions) => Not extends true ? Promise<Exclude<T, undefined>> : Promise<undefined>; toBeNaN: (options?: UntilToMatchOptions) => Promise<T>; } export interface UntilArrayInstance<T> extends UntilBaseInstance<T> { readonly not: UntilArrayInstance<T>; toContains: (value: MaybeRefOrGetter<ElementOf<ShallowUnwrapRef<T>>>, options?: UntilToMatchOptions) => Promise<T>; } export declare function until<T extends unknown[]>(r: WatchSource<T> | MaybeRefOrGetter<T>): UntilArrayInstance<T>; export declare function until<T>(r: WatchSource<T> | MaybeRefOrGetter<T>): UntilValueInstance<T>; export {};