Skip to content

isType ​

The isType() function creates a type guard based on typeof, Array.isArray, iterables, functions, etc. It allows narrowing a union to the checked type.

Interactive example ​

Syntax ​

Classic signature ​

typescript
function isType<
	GenericInput extends unknown,
	GenericType extends EligibleType<GenericInput>
>(
	input: GenericInput,
	type: GenericType
): input is ComputeResult<GenericInput, Type[GenericType]>;

Curried signature ​

typescript
function isType<
	GenericInput extends unknown,
	GenericType extends EligibleType<GenericInput>
>(
	type: GenericType
): (input: GenericInput) => input is ComputeResult<GenericInput, Type[GenericType]>;

Parameters ​

  • type : The runtime type to check.
  • input (direct overload) : Tested value.

Return value ​

A boolean acting as a type guard by narrowing the union to the requested type.

See also ​

Released under the MIT license.