All essential TypeScript types in one place providing 70+ utility types and helper functions.
npx @tessl/cli install tessl/npm-ts-essentials@10.1.0ts-essentials is a comprehensive collection of essential TypeScript utility types that enhance type safety and developer productivity. It provides over 70 carefully crafted utility types organized into categories such as basic types, utility types, mark wrapper types, deep wrapper types, and more.
npm install --save-dev ts-essentialsimport type { Prettify, StrictOmit, DeepPartial, NonEmptyArray, CamelCase, DeepCamelCaseProperties } from "ts-essentials";For CommonJS:
const { Prettify, StrictOmit, DeepPartial, NonEmptyArray, CamelCase, DeepCamelCaseProperties } = require("ts-essentials");All types are imported directly from the main module - no need for deep imports.
import type {
Prettify,
StrictOmit,
Merge,
DeepPartial,
NonEmptyArray,
Opaque
} from "ts-essentials";
// Basic type manipulation
type User = { id: number; name: string; email: string; };
type PublicUser = StrictOmit<User, "email">; // { id: number; name: string; }
// Merging types
type Settings = { theme: string; };
type UserWithSettings = Merge<User, Settings>; // Combined type
// Deep operations
type PartialUser = DeepPartial<User>; // All properties optional recursively
// Array constraints
type UserList = NonEmptyArray<User>; // Array with at least one User
// Branded types
type UserId = Opaque<number, "UserId">;
const userId: UserId = 123 as UserId;
// Case transformations
type ApiField = CamelCase<"user_name">; // "userName"
type TransformedApi = DeepCamelCaseProperties<{ user_id: number; user_name: string; }>;
// { userId: number; userName: string; }ts-essentials is organized into logical categories of type utilities:
Primitive, Prettify, and strict versions of built-in utilitiesCore TypeScript utility types providing strict alternatives to built-in utilities and essential building blocks.
type Primitive = string | number | boolean | bigint | symbol | undefined | null;
type Prettify<Type> = Type extends Function ? Type : { [Key in keyof Type]: Type[Key] };
type StrictOmit<Type extends Record<string | number | symbol, any>, Keys extends keyof Type> =
Type extends Array<any> ? never : Omit<Type, Keys>;
/** @deprecated Use built-in Awaited instead */
type Awaited<Type> = Type extends PromiseLike<infer Value> ? Value : never;Advanced type operations for merging, transforming, and manipulating complex type structures.
type Dictionary<Type, Keys extends KeyofBase = string> = { [key in Keys]: Type };
type Merge<Object1, Object2> = Prettify<Omit<Object1, keyof Object2> & Object2>;
type Opaque<Type, Token> = Type & { readonly __opaque__: Token };Transform specific properties of objects by changing their modifiers (optional, readonly, required, writable).
type MarkOptional<Type, Keys extends keyof Type> = Prettify<Omit<Type, Keys> & Partial<Pick<Type, Keys>>>;
type MarkRequired<Type, Keys extends keyof Type> = Prettify<Omit<Type, Keys> & Required<Pick<Type, Keys>>>;Recursive type transformations that apply operations to nested object structures at any depth.
type DeepPartial<Type> = Type extends Function
? Type
: Type extends Array<infer U>
? Array<DeepPartial<U>>
: Type extends ReadonlyArray<infer U>
? ReadonlyArray<DeepPartial<U>>
: { [K in keyof Type]?: DeepPartial<Type[K]> };
type DeepReadonly<Type> = Type extends Function
? Type
: Type extends Array<infer U>
? ReadonlyArray<DeepReadonly<U>>
: { readonly [K in keyof Type]: DeepReadonly<Type[K]> };Extract and work with object property keys based on their characteristics (optional, required, readonly, writable).
type OptionalKeys<Type> = { [K in keyof Type]-?: {} extends Pick<Type, K> ? K : never }[keyof Type];
type RequiredKeys<Type> = { [K in keyof Type]-?: {} extends Pick<Type, K> ? never : K }[keyof Type];Conditional types for runtime type validation and compile-time type detection.
type IsAny<Type> = 0 extends 1 & Type ? true : false;
type IsNever<Type> = [Type] extends [never] ? true : false;
type Exact<Type, Shape> = [Type] extends [Shape] ? [Shape] extends [Type] ? Type : never : never;Specialized types for working with arrays, tuples, and array-like structures with type safety.
type NonEmptyArray<Type> = [Type, ...Type[]];
type ElementOf<Type> = Type extends ReadonlyArray<infer U> ? U : never;
type Head<Type extends ReadonlyArray<any>> = Type extends readonly [infer H, ...any[]] ? H : never;String case transformation utilities for converting between different naming conventions at the type level.
type CamelCase<Type> = Type extends string ? /* converts any case to camelCase */ : Type;
type DeepCamelCaseProperties<Type> = Type extends Record<string, unknown>
? { [Key in keyof Type as CamelCase<Key>]: DeepCamelCaseProperties<Type[Key]> }
: Type;Type utilities for function signatures, predicates, and function-related operations.
type AnyFunction<Args extends ReadonlyArray<any> = any[], ReturnType = any> = (...args: Args) => ReturnType;
type PredicateFunction = <T, U extends T>(arg: T) => arg is U;Runtime functions that complement the type system, providing assertions, factories, and helper utilities.
function assert(condition: any, message?: string): asserts condition;
class UnreachableCaseError extends Error {
constructor(value: never);
}
function noop(..._args: any[]): void;