CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-ts-essentials

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

Pending
Overview
Eval results
Files

basic-types.mddocs/

Basic Types

Core TypeScript utility types providing strict alternatives to built-in utilities and essential building blocks for type manipulation.

Capabilities

Primitive

Matches any primitive value type including all JavaScript primitive types.

type Primitive = string | number | boolean | bigint | symbol | undefined | null;

Usage Example:

import type { Primitive } from "ts-essentials";

function isPrimitive(value: unknown): value is Primitive {
  return value !== Object(value);
}

type Config = {
  [key: string]: Primitive | Primitive[];
};

Builtin

Matches primitive, function, date, error, or regular expression types.

type Builtin = Primitive | Function | Date | Error | RegExp;

KeyofBase

A keyofStringsOnly-tolerant analogue for PropertyKey, used as a base type for object keys.

type KeyofBase = string | number | symbol;

Prettify

Flattens type definitions to make them more readable in IDE hover tooltips and error messages.

type Prettify<Type> = Type extends Function
  ? Type
  : Extract<
      {
        [Key in keyof Type]: Type[Key];
      },
      Type
    >;

Usage Example:

import type { Prettify, Merge } from "ts-essentials";

type User = { id: number; name: string; };
type Settings = { theme: string; lang: string; };

// Without Prettify: complex intersection type display
type UserSettings = User & Settings;

// With Prettify: clean, flat type display
type CleanUserSettings = Prettify<Merge<User, Settings>>;
// Result: { id: number; name: string; theme: string; lang: string; }

StrictExclude

Constructs a type by excluding from UnionType all union members that are assignable to ExcludedMembers. This is a stricter version of TypeScript's built-in Exclude.

type StrictExclude<UnionType, ExcludedMembers> = UnionType extends ExcludedMembers
  ? never
  : UnionType;

Usage Example:

import type { StrictExclude } from "ts-essentials";

type Colors = "red" | "green" | "blue" | "yellow";
type PrimaryColors = StrictExclude<Colors, "yellow">;
// Result: "red" | "green" | "blue"

StrictExtract

Constructs a type by extracting from Type all union members that are assignable to Union. This is a stricter version of TypeScript's built-in Extract.

type StrictExtract<Type, Union> = Type extends Union ? Type : never;

Usage Example:

import type { StrictExtract } from "ts-essentials";

type AllEvents = "click" | "hover" | "focus" | "scroll";
type MouseEvents = StrictExtract<AllEvents, "click" | "hover">;
// Result: "click" | "hover"

StrictOmit

Constructs a type by picking all properties from Type and then removing Keys. This is a stricter version of TypeScript's built-in Omit that prevents omitting from array types.

type StrictOmit<Type extends Record<string | number | symbol, any>, Keys extends keyof Type> = 
  Type extends Array<any> ? never : Omit<Type, Keys>;

Usage Example:

import type { StrictOmit } from "ts-essentials";

type User = {
  id: number;
  name: string;
  email: string;
  password: string;
};

type PublicUser = StrictOmit<User, "password" | "email">;
// Result: { id: number; name: string; }

// This would cause a compile error (preventing array omission):
// type InvalidArray = StrictOmit<string[], "length">; // never

Writable

Constructs a type with all readonly properties of Type converted to mutable, meaning the properties can be reassigned.

type Writable<Type> = {
  -readonly [Key in keyof Type]: Type[Key];
};

Usage Example:

import type { Writable } from "ts-essentials";

type ReadonlyUser = {
  readonly id: number;
  readonly name: string;
  email: string;
};

type MutableUser = Writable<ReadonlyUser>;
// Result: { id: number; name: string; email: string; }

const user: MutableUser = { id: 1, name: "Alice", email: "alice@example.com" };
user.id = 2; // OK - no longer readonly
user.name = "Bob"; // OK - no longer readonly

Awaited

A re-export of TypeScript's built-in Awaited utility type for recursively unwrapping Promise types.

/** @deprecated Use built-in Awaited instead */
type Awaited<Type> = Type extends PromiseLike<infer Value> ? Value : never;

Usage Example:

import type { Awaited } from "ts-essentials";

// Use built-in Awaited instead
type Result = Awaited<Promise<string>>; // string
type NestedResult = Awaited<Promise<Promise<number>>>; // number

Install with Tessl CLI

npx tessl i tessl/npm-ts-essentials

docs

array-tuple-types.md

basic-types.md

change-case-types.md

deep-wrapper-types.md

function-types.md

index.md

key-types.md

mark-wrapper-types.md

type-checkers.md

utility-functions.md

utility-types.md

tile.json