Skip to content

⬅️ Back to Table of Contents

📄 types.ts

📊 Analysis Summary

Metric Count
📦 Imports 7
📐 Interfaces 4
📑 Type Aliases 19

📚 Table of Contents

🛠️ File Location:

📂 packages/shared/utils/types.ts

📦 Imports

Name Source
ComputedRef vue
MaybeRef vue
MaybeRefOrGetter vue
Ref vue
ShallowRef vue
WatchOptions vue
WatchSource vue

Interfaces

Pausable

Interface Code
export interface Pausable {
  /**
   * A ref indicate whether a pausable instance is active
   */
  readonly isActive: Readonly<ShallowRef<boolean>>

  /**
   * Temporary pause the effect from executing
   */
  pause: Fn

  /**
   * Resume the effects
   */
  resume: Fn
}

Properties

Name Type Optional Description
isActive Readonly<ShallowRef<boolean>>
pause Fn
resume Fn

Stoppable<StartFnArgs extends any[] = any[]>

Interface Code
export interface Stoppable<StartFnArgs extends any[] = any[]> {
  /**
   * A ref indicate whether a stoppable instance is executing
   */
  readonly isPending: Readonly<Ref<boolean>>

  /**
   * Stop the effect from executing
   */
  stop: Fn

  /**
   * Start the effects
   */
  start: (...args: StartFnArgs) => void
}

Properties

Name Type Optional Description
isPending Readonly<Ref<boolean>>
stop Fn
start (...args: StartFnArgs) => void

ConfigurableFlush

Interface Code
export interface ConfigurableFlush {
  /**
   * Timing for monitoring changes, refer to WatchOptions for more details
   *
   * @default 'pre'
   */
  flush?: WatchOptions['flush']
}

Properties

Name Type Optional Description
flush WatchOptions['flush']

ConfigurableFlushSync

Interface Code
export interface ConfigurableFlushSync {
  /**
   * Timing for monitoring changes, refer to WatchOptions for more details.
   * Unlike `watch()`, the default is set to `sync`
   *
   * @default 'sync'
   */
  flush?: WatchOptions['flush']
}

Properties

Name Type Optional Description
flush WatchOptions['flush']

Type Aliases

Fn

/* * Void function /

type Fn = () => void;

AnyFn

/* * Any function /

type AnyFn = (...args: any[]) => any;

RemovableRef<T>

/* * A ref that allow to set null or undefined /

type RemovableRef<T> = Omit<Ref<T>, 'value'> & {
  get value(): T
  set value(value: T | null | undefined)
};

ReadonlyRefOrGetter<T>

/* * Maybe it's a computed ref, or a readonly value, or a getter function /

type ReadonlyRefOrGetter<T> = ComputedRef<T> | (() => T);

DeepMaybeRef<T>

/* * Make all the nested attributes of an object or array to MaybeRef * * Good for accepting options that will be wrapped with reactive or ref * * ts * UnwrapRef<DeepMaybeRef<T>> === T * /

type DeepMaybeRef<T> = T extends Ref<infer V>
  ? MaybeRef<V>
  : T extends Array<any> | object
    ? { [K in keyof T]: DeepMaybeRef<T[K]> }
    : MaybeRef<T>;

Arrayable<T>

type Arrayable<T> = T[] | T;

ElementOf<T>

/* * Infers the element type of an array /

type ElementOf<T> = T extends (infer E)[] ? E : never;

ShallowUnwrapRef<T>

type ShallowUnwrapRef<T> = T extends Ref<infer P> ? P : T;

Awaitable<T>

type Awaitable<T> = Promise<T> | T;

ArgumentsType<T>

type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never;

Awaited<T>

/* * Compatible with versions below TypeScript 4.5 Awaited /

type Awaited<T> = T extends null | undefined ? T : // special case for `null | undefined` when not in `--strictNullChecks` mode
    T extends object & { then: (onfulfilled: infer F, ...args: infer _) => any } ? // `await` only unwraps object types with a callable `then`. Non-object types are not unwrapped
      F extends ((value: infer V, ...args: infer _) => any) ? // if the argument to `then` is callable, extracts the first argument
        Awaited<V> : // recursively unwrap the value
        never : // the argument to `then` was not callable
      T;

Promisify<T>

type Promisify<T> = Promise<Awaited<T>>;

PromisifyFn<T extends AnyFn extends AnyFn>

type PromisifyFn<T extends AnyFn extends AnyFn> = (...args: ArgumentsType<T>) => Promisify<ReturnType<T>>;

MultiWatchSources

type MultiWatchSources = (WatchSource<unknown> | object)[];

MapSources<T>

type MapSources<T> = {
  [K in keyof T]: T[K] extends WatchSource<infer V> ? V : never;
};

MapOldSources<T, Immediate>

type MapOldSources<T, Immediate> = {
  [K in keyof T]: T[K] extends WatchSource<infer V> ? Immediate extends true ? V | undefined : V : never;
};

Mutable<T>

type Mutable<T> = { -readonly [P in keyof T]: T[P] };

IfAny<T, Y, N>

type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;

IsAny<T>

/* * will return true if T is any, or false otherwise /

type IsAny<T> = IfAny<T, true, false>;