Skip to content

Types

The types module provides a comprehensive set of functions for type checking and identification in JavaScript/TypeScript. These functions are designed to offer a safe and reliable way to check data types, including primitive types, objects, special functions, and native JavaScript data structures.

Key features:

  • Accurate checking of primitive types (string, number, boolean, etc.)
  • Support for special types like Promise, Generator, and async functions
  • Identification of data structures (Map, Set, WeakMap, etc.)
  • Detection of null/undefined values and falsy checks
  • TypeScript typing for greater safety and autocompletion

All functions are optimized for performance and follow best practices for type checking in JavaScript.

Overview

getInstanceType

typescript
getInstanceType(value: any): string | null;

Returns the constructor (class) name of an instance, or null if not applicable.

getType

typescript
getType(value: any): string;

Returns a string representing the value's type, including special cases like "nan", "infinity", "null", and "array".

isArray

typescript
isArray(value: any): value is any[];

Checks if the value is an array.

isAsyncFunction

typescript
isAsyncFunction(value: any): value is (...args: any[]) => Promise<any>;

Checks if the value is an async function.

isAsyncGeneratorFunction

typescript
isAsyncGeneratorFunction(value: any): value is AsyncGeneratorFunction;

Checks if the value is an async generator function.

isBigint

typescript
isBigint(value: any): value is bigint;

Checks if the value is of type bigint.

isBoolean

typescript
isBoolean(value: any): value is boolean;

Checks if the value is of type boolean.

isDate

typescript
isDate(value: any): value is Date;

Checks if the value is an instance of Date.

isFalsy

typescript
isFalsy(value: any): boolean;

Checks if the value is considered falsy in JavaScript.

isFunction

typescript
isFunction(value: any): value is Function;

Checks if the value is a function.

isGeneratorFunction

typescript
isGeneratorFunction(value: any): value is GeneratorFunction;

Checks if the value is a generator function.

isMap

typescript
isMap(value: any): value is Map<any, any>;

Checks if the value is an instance of Map.

isNil

typescript
isNil(value: any): value is null | undefined;

Checks if the value is null or undefined.

isNull

typescript
isNull(value: any): value is null;

Checks if the value is exactly null.

isNumber

typescript
isNumber(value: any): value is number;

Checks if the value is of type number.

isObject

typescript
isObject(value: any): value is object;

Checks if the value is an object (excluding null).

isPrimitive

typescript
isPrimitive(value: any): value is (string | number | boolean | symbol | bigint | null | undefined);

Checks if the value is a primitive type: string, number, boolean, symbol, bigint, null, or undefined.

isPromise

typescript
isPromise<T = any>(value: any): value is Promise<T>;

Checks if the value is a Promise.

isRegExp

typescript
isRegExp(value: any): value is RegExp;

Checks if the value is a regular expression (RegExp).

isSet

typescript
isSet(value: any): value is Set<any>;

Checks if the value is an instance of Set.

isString

typescript
isString(value: any): value is string;

Checks if the value is of type string.

isSymbol

typescript
isSymbol(value: any): value is symbol;

Checks if the value is of type symbol.

isUndefined

typescript
isUndefined(value: any): value is undefined;

Checks if the value is undefined.

isWeakMap

typescript
isWeakMap(value: any): value is WeakMap<object, any>;

Checks if the value is an instance of WeakMap.

isWeakRef

typescript
isWeakRef(value: any): value is WeakRef<any>;

Checks if the value is an instance of WeakRef.

isWeakSet

typescript
isWeakSet(value: any): value is WeakSet<object>;

Checks if the value is an instance of WeakSet.

Released under the MIT License.