or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

array-tuple-types.mdbasic-types.mdchange-case-types.mddeep-wrapper-types.mdfunction-types.mdindex.mdkey-types.mdmark-wrapper-types.mdtype-checkers.mdutility-functions.mdutility-types.md
tile.json

tessl/npm-ts-essentials

All essential TypeScript types in one place providing 70+ utility types and helper functions.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/ts-essentials@10.1.x

To install, run

npx @tessl/cli install tessl/npm-ts-essentials@10.1.0

index.mddocs/

ts-essentials

ts-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.

Package Information

  • Package Name: ts-essentials
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install --save-dev ts-essentials
  • TypeScript Version: >=4.5.0 required
  • Requirements: strictNullChecks must be enabled

Core Imports

import 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.

Basic Usage

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; }

Architecture

ts-essentials is organized into logical categories of type utilities:

  • Basic Types: Core building blocks like Primitive, Prettify, and strict versions of built-in utilities
  • Utility Types: Advanced type operations for objects, unions, and transformations
  • Mark Wrapper Types: Modify specific properties (optional, readonly, required, writable)
  • Deep Wrapper Types: Recursive type transformations that work on nested structures
  • Key Types: Extract and work with object property keys
  • Type Checkers: Conditional types for type validation and detection
  • Array & Tuple Types: Specialized types for array and tuple operations
  • Change Case Types: String case transformation utilities for different naming conventions
  • Function Types: Type utilities for function signatures and predicates
  • Utility Functions: Runtime functions that complement the type system

Capabilities

Basic Types

Core 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;

Basic Types

Utility Types

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 };

Utility Types

Mark Wrapper Types

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>>>;

Mark Wrapper Types

Deep Wrapper Types

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]> };

Deep Wrapper Types

Key Types

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];

Key Types

Type Checkers

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;

Type Checkers

Array & Tuple Types

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;

Array & Tuple Types

Change Case Types

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;

Change Case Types

Function Types

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;

Function Types

Utility Functions

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;

Utility Functions