Skip to content

⬅️ Back to Table of Contents

📄 utils/types

📊 Analysis Summary

Metric Count
📦 Imports 7
🔄 Re-exports 1
📐 Interfaces 4
📑 Type Aliases 21

📚 Table of Contents

🛠️ File Location:

📂 packages/shared/utils/types.ts

📦 Imports

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

Re-exports

Type Source Exported Names
named vue MultiWatchSources

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>> not shown
pause Fn not shown
resume Fn not shown

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>> not shown
stop Fn not shown
start (...args: StartFnArgs) => void not shown

ConfigurableFlush

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

Properties

Name Type Optional Description
flush WatchOptionFlush not shown

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?: WatchOptionFlush
}

Properties

Name Type Optional Description
flush WatchOptionFlush not shown

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> = Ref<T, 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>

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

WatchOptionFlush

type WatchOptionFlush = WatchOptions['flush'];

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>;

TimerHandle

/* * Universal timer handle that works in both browser and Node.js environments /

type TimerHandle = ReturnType<typeof setTimeout> | undefined;

InstanceProxy

type InstanceProxy = NonNullable<NonNullable<ReturnType<typeof getCurrentInstance>>['proxy']>;

Generated by Syntax Scribe