Options
All
  • Public
  • Public/Protected
  • All
Menu

@tool-belt/type-predicates - v1.2.0

Index

Type aliases

Type Assertion Functions

Type Guard Functions

Utility Functions

Type aliases

AsyncFunction

AsyncFunction<T>: (...args: any[]) => Promise<T>

Type parameters

  • T = unknown

Type declaration

    • (...args: any[]): Promise<T>
    • Parameters

      • Rest ...args: any[]

      Returns Promise<T>

ErrorMessage

ErrorMessage: { message: string | undefined }

Type declaration

  • message: string | undefined

KeyValidator

KeyValidator: { keyValidator: TypeValidator }

Type declaration

TypeAssertion

TypeAssertion<T, O>: (input: unknown, options?: O) => asserts input is T

Type parameters

Type declaration

    • (input: unknown, options?: O): asserts input is T
    • Parameters

      • input: unknown
      • Optional options: O

      Returns asserts input is T

TypeAssertionOptions

TypeAssertionOptions: TypeGuardOptions & Partial<ErrorMessage>

TypeGuard

TypeGuard<T, O>: (input: unknown, options?: O) => input is T

Type parameters

Type declaration

    • (input: unknown, options?: O): input is T
    • Parameters

      • input: unknown
      • Optional options: O

      Returns input is T

TypeGuardOptions

TypeGuardOptions: Partial<ValueValidator & KeyValidator>

TypeValidator

TypeValidator: (input: unknown, ...args: any[]) => boolean

Type declaration

    • (input: unknown, ...args: any[]): boolean
    • Parameters

      • input: unknown
      • Rest ...args: any[]

      Returns boolean

TypedArray

TypedArray: Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array | BigUint64Array | BigInt64Array | Float32Array | Float64Array

TypedAsyncGeneratorFunction

TypedAsyncGeneratorFunction<Y, R, N>: (...args: any[]) => AsyncGenerator<Y, R, N>

Type parameters

  • Y

  • R

  • N

Type declaration

    • (...args: any[]): AsyncGenerator<Y, R, N>
    • Parameters

      • Rest ...args: any[]

      Returns AsyncGenerator<Y, R, N>

TypedGeneratorFunction

TypedGeneratorFunction<Y, R, N>: (...args: any[]) => Generator<Y, R, N>

Type parameters

  • Y

  • R

  • N

Type declaration

    • (...args: any[]): Generator<Y, R, N>
    • Parameters

      • Rest ...args: any[]

      Returns Generator<Y, R, N>

ValueValidator

ValueValidator: { valueValidator: TypeValidator }

Type declaration

Type Assertion Functions

Const assertIsAnyArrayBuffer

  • assertIsAnyArrayBuffer(input: unknown, options?: ErrorMessage): asserts input is ArrayBuffer | SharedArrayBuffer

assertIsArray

  • assertIsArray(input: unknown): asserts input is any[]
  • assertIsArray(input: unknown, options?: ErrorMessage): asserts input is any[]
  • assertIsArray<T>(input: unknown, options: ValueValidator): asserts input is T[]
  • assertIsArray<T>(input: unknown, options: ValueValidator & ErrorMessage): asserts input is T[]

Const assertIsArrayBuffer

  • assertIsArrayBuffer(input: unknown, options?: ErrorMessage): asserts input is ArrayBuffer

assertIsAsyncFunction

assertIsAsyncGenerator

  • assertIsAsyncGenerator<Y, R, N>(input: unknown, options?: ErrorMessage): asserts input is AsyncGenerator<Y, R, N>
  • remarks

    This assertion works only in ES2018 and above

    throws

    TypeError

    Type parameters

    • Y = unknown

    • R = unknown

    • N = unknown

    Parameters

    Returns asserts input is AsyncGenerator<Y, R, N>

assertIsAsyncGeneratorFunction

assertIsAsyncIterable

  • assertIsAsyncIterable<T>(input: unknown, options?: ErrorMessage): asserts input is AsyncIterable<T>

Const assertIsBigInt

  • assertIsBigInt(input: unknown, options?: ErrorMessage): asserts input is bigint
  • example
    // does not throw
    assertIsBigInt(BigInt(9007199254740991));
    
    // throws
    assertIsBigInt(9007199254740991n);
    
    throws

    TypeError

    Parameters

    Returns asserts input is bigint

Const assertIsBigInt64Array

  • assertIsBigInt64Array(input: unknown, options?: ErrorMessage): asserts input is BigInt64Array

Const assertIsBigUint64Array

  • assertIsBigUint64Array(input: unknown, options?: ErrorMessage): asserts input is BigUint64Array

Const assertIsBoolean

  • assertIsBoolean(input: unknown, options?: ErrorMessage): asserts input is boolean

Const assertIsBooleanObject

  • assertIsBooleanObject(input: unknown, options?: ErrorMessage): asserts input is Boolean

Const assertIsBuffer

  • assertIsBuffer(input: unknown, options?: ErrorMessage): asserts input is Buffer

Const assertIsDataView

  • assertIsDataView(input: unknown, options?: ErrorMessage): asserts input is DataView

Const assertIsDate

  • assertIsDate(input: unknown, options?: ErrorMessage): asserts input is Date

assertIsDefined

  • assertIsDefined<T>(input: T | undefined, options?: ErrorMessage): asserts input is T
  • remarks

    This assertion asserts that the value is not null, use assertIsNotNullish to also exclude undefined

    throws

    TypeError

    Type parameters

    • T

    Parameters

    Returns asserts input is T

assertIsError

  • assertIsError<T>(input: unknown, options?: ErrorMessage): asserts input is T
  • example
    // does not throw, value is typed as Error
    assertIsError(new Error());
    
    // does not throw, value is typed as Error
    assertIsError<TypeError>(new TypeError());
    
    // does not throw, value is typed as TypeError
    assertIsError<TypeError>(new TypeError());
    
    // does not throw, value is typed as MyError - if MyError inherits from Error or its sub-classes
    assertIsError<MyError>(new MyError());
    
    throws

    TypeError

    Type parameters

    • T: Error = Error

    Parameters

    Returns asserts input is T

Const assertIsFloat32Array

  • assertIsFloat32Array(input: unknown, options?: ErrorMessage): asserts input is Float32Array

Const assertIsFloat64Array

  • assertIsFloat64Array(input: unknown, options?: ErrorMessage): asserts input is Float64Array

assertIsFunction

  • assertIsFunction<T>(input: unknown, options?: ErrorMessage): asserts input is T
  • remarks

    This guard works only in ES2018 and above

    example
    // does not throw, value is typed as Function
    assertIsFunction(() => true);
    
    // does not throw, value is typed as () => boolean
    assertIsFunction<() => boolean>(() => true);
    
    // throws
    assertIsFunction(async () => Promise.resolve(null));
    
    // throws
    assertIsFunction(function* () {});
    
    // throws
    assertIsFunction(async function* () {});
    
    // throws
    assertIsFunction(MyClass);
    
    throws

    TypeError

    Type parameters

    • T: Function = Function

    Parameters

    Returns asserts input is T

assertIsGenerator

  • assertIsGenerator<Y, R, N>(input: unknown, options?: ErrorMessage): asserts input is Generator<Y, R, N>
  • remarks

    This assertion works only in ES2018 and above

    throws

    TypeError

    Type parameters

    • Y = unknown

    • R = unknown

    • N = unknown

    Parameters

    Returns asserts input is Generator<Y, R, N>

assertIsGeneratorFunction

Const assertIsInt16Array

  • assertIsInt16Array(input: unknown, options?: ErrorMessage): asserts input is Int16Array

Const assertIsInt32Array

  • assertIsInt32Array(input: unknown, options?: ErrorMessage): asserts input is Int32Array

Const assertIsInt8Array

  • assertIsInt8Array(input: unknown, options?: ErrorMessage): asserts input is Int8Array

assertIsIterable

  • assertIsIterable<T>(input: unknown, options?: ErrorMessage): asserts input is Iterable<T>

assertIsIterator

  • assertIsIterator<Y, R, N>(input: unknown, options?: ErrorMessage): asserts input is Iterator<Y, R, N>
  • remarks

    This assertion works only in ES2018 and above

    throws

    TypeError

    Type parameters

    • Y = unknown

    • R = unknown

    • N = unknown

    Parameters

    Returns asserts input is Iterator<Y, R, N>

assertIsMap

  • assertIsMap(input: unknown): asserts input is Map<unknown, unknown>
  • assertIsMap(input: unknown, options?: ErrorMessage): asserts input is Map<unknown, unknown>
  • assertIsMap<K>(input: unknown, options: KeyValidator): asserts input is Map<K, unknown>
  • assertIsMap<K>(input: unknown, options: KeyValidator & ErrorMessage): asserts input is Map<K, unknown>
  • assertIsMap<V>(input: unknown, options: ValueValidator): asserts input is Map<string, V>
  • assertIsMap<V>(input: unknown, options: ValueValidator & ErrorMessage): asserts input is Map<string, V>
  • assertIsMap<K, V>(input: unknown, options: ValueValidator & KeyValidator): asserts input is Map<K, V>
  • assertIsMap<K, V>(input: unknown, options: ValueValidator & KeyValidator & ErrorMessage): asserts input is Map<K, V>

assertIsNotNull

  • assertIsNotNull<T>(input: T | null, options?: ErrorMessage): asserts input is T
  • remarks

    This assertion asserts that the value is not null, use assertIsNotNullish to also exclude undefined

    throws

    TypeError

    Type parameters

    • T

    Parameters

    Returns asserts input is T

assertIsNotNullish

  • assertIsNotNullish<T>(input: T | undefined | null, options?: ErrorMessage): asserts input is T
  • remarks

    Tests false for undefined and null, true for all other values

    throws

    TypeError

    Type parameters

    • T

    Parameters

    • input: T | undefined | null
    • Optional options: ErrorMessage

    Returns asserts input is T

Const assertIsNull

  • assertIsNull(input: unknown, options?: ErrorMessage): asserts input is null

Const assertIsNullish

  • assertIsNullish(input: unknown, options?: ErrorMessage): asserts input is undefined | null

Const assertIsNumber

  • assertIsNumber(input: unknown, options?: ErrorMessage): asserts input is number
  • example
    // does not throw
    assertIsNumber(1);
    
    // throws
    assertIsNumber(new Number(1));
    
    throws

    TypeError

    Parameters

    Returns asserts input is number

Const assertIsNumberObject

  • assertIsNumberObject(input: unknown, options?: ErrorMessage): asserts input is Number
  • example
    // does not throw
    assertIsNumberObject(new Number(1));
    
    // throws
    assertIsNumberObject(1);
    
    throws

    TypeError

    Parameters

    Returns asserts input is Number

Const assertIsObject

  • assertIsObject(input: unknown, options?: ErrorMessage): asserts input is object
  • remarks

    Tests true for all objects that have a typeof 'object' excluding null

    example
    // does not throw, value is typed as object
    assertIsObject({});
    
    // does not throw, value is typed as object
    assertIsObject([]);
    
    // throws
    assertIsObject(null);
    
    throws

    TypeError

    Parameters

    Returns asserts input is object

assertIsPromise

  • assertIsPromise<T>(input: unknown, options?: ErrorMessage): asserts input is Promise<T>
  • remarks

    Works with custom promises as well, e.g. AxiosPromise or BlueBird

    throws

    TypeError

    Type parameters

    • T = unknown

    Parameters

    Returns asserts input is Promise<T>

assertIsRecord

  • assertIsRecord(input: unknown): asserts input is Record<string | symbol, unknown>
  • assertIsRecord(input: unknown, options?: ErrorMessage): asserts input is Record<string | symbol, unknown>
  • assertIsRecord<K>(input: unknown, options: KeyValidator): asserts input is Record<K, unknown>
  • assertIsRecord<K>(input: unknown, options: KeyValidator & ErrorMessage): asserts input is Record<K, unknown>
  • assertIsRecord<V>(input: unknown, options: ValueValidator): asserts input is Record<string, V>
  • assertIsRecord<V>(input: unknown, options: ValueValidator & ErrorMessage): asserts input is Record<string, V>
  • assertIsRecord<K, V>(input: unknown, options: ValueValidator & KeyValidator): asserts input is Record<K, V>
  • assertIsRecord<K, V>(input: unknown, options: ValueValidator & KeyValidator & ErrorMessage): asserts input is Record<K, V>

Const assertIsRegExp

  • assertIsRegExp(input: unknown, options?: ErrorMessage): asserts input is RegExp
  • example
    // does not throw
    assertIsRegExp(new RegExp('abc'));
    
    // does not throw
    assertIsRegExp(/'abc'/);
    
    throws

    TypeError

    Parameters

    Returns asserts input is RegExp

assertIsSet

  • assertIsSet(input: unknown): asserts input is Set<any>
  • assertIsSet(input: unknown, options: ErrorMessage): asserts input is Set<any>
  • assertIsSet<T>(input: unknown, options: ValueValidator): asserts input is Set<T>
  • example
    // doesn't throw, value is typed as Set<any>
    assertIsSet(new Set(['xyz']));
    
    // doesn't throw, value is typed as Set<string>
    assertIsSet<string>(new Set(['xyz']), { valueValidator: isString });
    
    throws

    TypeError

    Parameters

    • input: unknown

    Returns asserts input is Set<any>

  • Parameters

    Returns asserts input is Set<any>

  • Type parameters

    • T

    Parameters

    Returns asserts input is Set<T>

Const assertIsSharedArrayBuffer

  • assertIsSharedArrayBuffer(input: unknown, options?: ErrorMessage): asserts input is SharedArrayBuffer

Const assertIsString

  • assertIsString(input: unknown, options?: ErrorMessage): asserts input is string

Const assertIsStringObject

  • assertIsStringObject(input: unknown, options?: ErrorMessage): asserts input is String

Const assertIsSymbol

  • assertIsSymbol(input: unknown, options?: ErrorMessage): asserts input is symbol

Const assertIsTypedArray

Const assertIsUint16Array

  • assertIsUint16Array(input: unknown, options?: ErrorMessage): asserts input is Uint16Array

Const assertIsUint32Array

  • assertIsUint32Array(input: unknown, options?: ErrorMessage): asserts input is Uint32Array

Const assertIsUint8Array

  • assertIsUint8Array(input: unknown, options?: ErrorMessage): asserts input is Uint8Array

Const assertIsUint8ClampedArray

  • assertIsUint8ClampedArray(input: unknown, options?: ErrorMessage): asserts input is Uint8ClampedArray

Const assertIsUndefined

  • assertIsUndefined(input: unknown, options?: ErrorMessage): asserts input is undefined

assertIsWeakMap

  • assertIsWeakMap<K, V>(input: unknown, options?: ErrorMessage): asserts input is WeakMap<K, V>

assertIsWeakSet

  • assertIsWeakSet<T>(input: unknown, options?: ErrorMessage): asserts input is WeakSet<T>

Type Guard Functions

Const isAnyArrayBuffer

  • isAnyArrayBuffer(input: unknown, options?: undefined): input is ArrayBuffer | SharedArrayBuffer
  • Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is ArrayBuffer | SharedArrayBuffer

isArray

  • isArray(input: unknown): input is any[]
  • isArray<T>(input: unknown, options: ValueValidator): input is T[]
  • example
    // true, typed as any[]
    isArray(['xyz']);
    
    // true, typed as string[]
    isArray<string>(['xyz'], { valueValidator: isString });
    

    Parameters

    • input: unknown

    Returns input is any[]

  • Type parameters

    • T

    Parameters

    Returns input is T[]

Const isArrayBuffer

  • isArrayBuffer(input: unknown, options?: undefined): input is ArrayBuffer

isAsyncFunction

isAsyncGenerator

  • isAsyncGenerator<Y, R, N>(input: unknown): input is AsyncGenerator<Y, R, N>
  • remarks

    This guard works only in ES2018 and above

    Type parameters

    • Y = unknown

    • R = unknown

    • N = unknown

    Parameters

    • input: unknown

    Returns input is AsyncGenerator<Y, R, N>

isAsyncGeneratorFunction

isAsyncIterable

  • isAsyncIterable<T>(input: unknown): input is AsyncIterable<T>

Const isBigInt

  • isBigInt(input: unknown, options?: undefined): input is bigint
  • example
    // true
    isBigInt(BigInt(9007199254740991));
    
    // true
    isBigInt(9007199254740991n);
    

    Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is bigint

Const isBigInt64Array

  • isBigInt64Array(input: unknown): input is BigInt64Array

Const isBigUint64Array

  • isBigUint64Array(input: unknown): input is BigUint64Array

Const isBoolean

  • isBoolean(input: unknown, options?: undefined): input is boolean
  • example
    // true
    isBoolean(false);
    
    // false
    isBoolean(new Boolean(false));
    

    Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is boolean

Const isBooleanObject

  • isBooleanObject(input: unknown, options?: undefined): input is Boolean
  • example
    // true
    isBooleanObject(new Boolean(true));
    
    // false
    isBooleanObject(true);
    

    Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is Boolean

Const isBuffer

  • isBuffer(input: unknown, options?: undefined): input is Buffer
  • Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is Buffer

Const isDataView

  • isDataView(input: unknown, options?: undefined): input is DataView
  • Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is DataView

Const isDate

  • isDate(input: unknown, options?: undefined): input is Date
  • Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is Date

isDefined

  • isDefined<T>(input: T | undefined): input is T

isError

  • isError<T>(input: unknown): input is T
  • example
    // true
    isError(new Error());
    
    // true, value is typed as Error
    isError(new TypeError());
    
    // true, value is typed as TypeError
    isError<TypeError>(new TypeError());
    
    // true, as long as MyCustomError inherits Error
    isError<MyCustomError>(new MyCustomError());
    

    Type parameters

    • T: Error = Error

    Parameters

    • input: unknown

    Returns input is T

Const isFloat32Array

  • isFloat32Array(input: unknown): input is Float32Array

Const isFloat64Array

  • isFloat64Array(input: unknown): input is Float64Array

isFunction

  • isFunction<T>(input: unknown): input is T
  • remarks

    This guard works only in ES2018 and above

    example
    // true, value is typed as Function
    isFunction(() => null);
    
    // true, value is typed as () => null
    isFunction<() => null>(() => null);
    
    // false
    isFunction(async () => Promise.resolve(null));
    
    // false
    isFunction(function* () {});
    
    // false
    isFunction(async function* () {});
    
    // false
    isFunction(MyClass);
    

    Type parameters

    • T: Function = Function

    Parameters

    • input: unknown

    Returns input is T

isGenerator

  • isGenerator<Y, R, N>(input: unknown): input is Generator<Y, R, N>
  • Type parameters

    • Y = unknown

    • R = unknown

    • N = unknown

    Parameters

    • input: unknown

    Returns input is Generator<Y, R, N>

isGeneratorFunction

Const isInt16Array

  • isInt16Array(input: unknown): input is Int16Array

Const isInt32Array

  • isInt32Array(input: unknown): input is Int32Array

Const isInt8Array

  • isInt8Array(input: unknown): input is Int8Array

isIterable

  • isIterable<T>(input: unknown): input is Iterable<T>

isIterator

  • isIterator<Y, R, N>(input: unknown): input is Iterator<Y, R, N>

isMap

  • isMap(input: unknown): input is Map<any, any>
  • isMap<K>(input: unknown, options: KeyValidator): input is Map<K, unknown>
  • isMap<V>(input: unknown, options: ValueValidator): input is Map<unknown, V>
  • isMap<K, V>(input: unknown, options: ValueValidator & KeyValidator): input is Map<K, V>
  • example
    // true, value is typed as Map<unknown, unknown>
    isMap(new Map([['xyz', 'abc']]));
    
    // true, value is typed as Map<string, string | number>
    isMap<string, string>(
        new Map([
            ['abc', 'def'],
            ['xyz', 100],
        ]),
        {
            keyValidator: isString,
            valueValidator: isUnion(isString, isNumber),
        },
    );
    

    Parameters

    • input: unknown

    Returns input is Map<any, any>

  • Type parameters

    • K

    Parameters

    Returns input is Map<K, unknown>

  • Type parameters

    • V

    Parameters

    Returns input is Map<unknown, V>

  • Type parameters

    • K

    • V

    Parameters

    Returns input is Map<K, V>

isNotNull

  • isNotNull<T>(input: T | null): input is T
  • remarks

    This guard checks that the value is not null, use isNotNullish to also exclude undefined

    Type parameters

    • T

    Parameters

    • input: T | null

    Returns input is T

isNotNullish

  • isNotNullish<T>(input: T | undefined | null): input is NonNullable<T>
  • remarks

    Tests false for undefined and null, true for all other values

    Type parameters

    • T

    Parameters

    • input: T | undefined | null

    Returns input is NonNullable<T>

Const isNull

  • isNull(input: unknown, options?: undefined): input is null
  • Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is null

Const isNullish

  • isNullish(input: unknown, options?: undefined): input is undefined | null
  • remarks

    Tests true for undefined and null, false for all other falsy values

    Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is undefined | null

Const isNumber

  • isNumber(input: unknown, options?: undefined): input is number
  • example
    // true
    isNumber(1);
    
    // false
    isNumber(new Number(1));
    
    // false
    isNumber(new BigInt(9007199254740991n));
    

    Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is number

Const isNumberObject

  • isNumberObject(input: unknown, options?: undefined): input is Number
  • example
    // true
    isNumberObject(new Number(1));
    
    // false
    isNumberObject(1);
    

    Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is Number

Const isObject

  • isObject(input: unknown, options?: undefined): input is object
  • remarks

    Tests true for all objects that have a typeof 'object' excluding null

    example
    // true
    isObject({});
    
    // true
    isObject([]);
    
    // false
    isObject(null);
    

    Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is object

isPromise

  • isPromise<T>(input: unknown): input is Promise<T>
  • remarks

    Works with custom promises as well, e.g. AxiosPromise or Bluebird

    Type parameters

    • T = unknown

    Parameters

    • input: unknown

    Returns input is Promise<T>

isRecord

  • isRecord(input: unknown): input is Record<string | symbol, any>
  • isRecord<K>(input: unknown, options: KeyValidator): input is Record<K, unknown>
  • isRecord<V>(input: unknown, options: ValueValidator): input is Record<string, V>
  • isRecord<K, V>(input: unknown, options: ValueValidator & KeyValidator): input is Record<K, V>
  • example
     * // true, value is typed as Record<string | symbol, any>
    isRecord(
        { key1: 'aaa', key2: 123 },
    );
    
    // true, value is typed as Record<string, string | number>
    isRecord<string, string | number>(
        { key1: 'aaa', key2: 123 },
        {
            keyValidator: isString,
            valueValidator: isUnion(isString, isNumber),
        },
    );
    

    Parameters

    • input: unknown

    Returns input is Record<string | symbol, any>

  • Type parameters

    • K: string | symbol

    Parameters

    Returns input is Record<K, unknown>

  • Type parameters

    • V

    Parameters

    Returns input is Record<string, V>

  • Type parameters

    • K: string | symbol

    • V

    Parameters

    Returns input is Record<K, V>

Const isRegExp

  • isRegExp(input: unknown, options?: undefined): input is RegExp
  • example
    // true
    isRegExp(new RegExp('somePattern'));
    
    // true
    isRegExp(/somePattern/);
    

    Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is RegExp

isSet

  • isSet(input: unknown): input is Set<any>
  • isSet<T>(input: unknown, options: ValueValidator): input is Set<T>
  • example
    // true, value is typed as Set<any>
    isSet(new Set(['xyz']));
    
    // true, value is typed as Set<string>
    isSet<string>(new Set(['xyz']), { valueValidator: isString });
    

    Parameters

    • input: unknown

    Returns input is Set<any>

  • Type parameters

    • T

    Parameters

    Returns input is Set<T>

Const isSharedArrayBuffer

  • isSharedArrayBuffer(input: unknown, options?: undefined): input is SharedArrayBuffer

Const isString

  • isString(input: unknown, options?: undefined): input is string
  • example
    // true
    isString('xyz');
    
    // false
    isString(new String('xyz'));
    

    Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is string

Const isStringObject

  • isStringObject(input: unknown, options?: undefined): input is String
  • example
    // true
    isStringObject(new String('xyz'));
    
    // false
    isStringObject('xyz');
    

    Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is String

Const isSymbol

  • isSymbol(input: unknown, options?: undefined): input is symbol
  • Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is symbol

Const isTypedArray

  • isTypedArray(input: unknown, options?: undefined): input is TypedArray

Const isUint16Array

  • isUint16Array(input: unknown): input is Uint16Array

Const isUint32Array

  • isUint32Array(input: unknown): input is Uint32Array

Const isUint8Array

  • isUint8Array(input: unknown): input is Uint8Array

Const isUint8ClampedArray

  • isUint8ClampedArray(input: unknown): input is Uint8ClampedArray

Const isUndefined

  • isUndefined(input: unknown, options?: undefined): input is undefined
  • Parameters

    • input: unknown
    • Optional options: undefined

    Returns input is undefined

isWeakMap

  • isWeakMap<K, V>(input: unknown): input is WeakMap<K, V>
  • Type parameters

    • K: object = any

    • V = unknown

    Parameters

    • input: unknown

    Returns input is WeakMap<K, V>

isWeakSet

  • isWeakSet<T>(input: unknown): input is WeakSet<T>
  • Type parameters

    • T: object = any

    Parameters

    • input: unknown

    Returns input is WeakSet<T>

Utility Functions

createTypeAssertion

createTypeGuard

  • example
    // myTypeGuard === (input: unknown, { throwError: boolean }) => input is MyClass
    const myTypeGuard = createTypeGuard<MyClass>(
        (value) => isObject(value) && Reflect.get(value, 'myProp'),
        MyClass.name,
    );
    

    Type parameters

    Parameters

    Returns TypeGuard<T, O>

isUnion

  • example
    // unionTypeGuard === <T>(input: unknown, ...args: any[]) => input is T
    const unionTypeGuard = isUnion<string | number | symbol>(
        isString,
        isNumber,
        isSymbol,
    );
    

    Type parameters

    • T

    Parameters

    Returns TypeGuard<T>

Generated using TypeDoc