Essential utilities for TypeScript projects

Downloads in past


497180.11.07 months agoa year agoMinified + gzip package size for ts-extras in KB


ts-extras Docs
Essential utilities for TypeScript projects

Still early in development. Ideas for additional essential utilities welcome. Type-only utilities belong in type-fest.


npm install ts-extras


import {isDefined} from 'ts-extras';

[1, undefined, 2].filter(isDefined);
//=> [1, 2]



Type guard
  • isDefined - Check whether a value is defined (not undefined).
  • isPresent - Check whether a value is present (not null or undefined).
  • isEmpty - Check whether an array is empty.
  • assertError - Assert that the given value is an Error.
  • isInfinite - Check whether a value is infinite.

Improved builtin
  • arrayIncludes - An alternative to Array#includes() that properly acts as a type guard.
  • setHas - An alternative to Set#has() that properly acts as a type guard.
  • objectKeys - A strongly-typed version of Object.keys().
  • objectEntries - A strongly-typed version of Object.entries().
  • objectFromEntries - A strongly-typed version of Object.fromEntries().
  • objectHasOwn - A strongly-typed version of Object.hasOwn().
  • isFinite - A strongly-typed version of Number.isFinite().
  • isInteger - A strongly-typed version of Number.isInteger().
  • isSafeInteger - A strongly-typed version of Number.isSafeInteger().


What is the difference between this and type-fest?

The type-fest package contains only types, meaning they are only used at compile-time and nothing is ever compiled into actual JavaScript code. This package contains functions that are compiled into JavaScript code and used at runtime.


  • type-fest - A collection of essential TypeScript types
  • is - Type guards for any situation