type-plus

raw JSON →
7.6.2 verified Sat Apr 25 auth: no javascript

Type utility library providing over 100 advanced TypeScript types for type-level programming. Current stable version is 7.6.2, released on npm with a moderate release cadence. It offers a wide range of type utilities such as numeric operations, object manipulation, array utilities, logical types, and assertion helpers. Key differentiators include a comprehensive set of type-level functions, support for advanced types like `$Equal`, `$Exact`, `Distributive`, and `AdjustExactOptionalProps`, along with built-in support for ESM and CJS. The library is actively maintained with a beta for v8.0.0 introducing breaking changes like renaming of types and ESM-only mode.

error Excessive stack depth comparing types
cause Complex recursive types like `Zeros` cause TypeScript to exceed stack depth.
fix
Upgrade to type-plus@7.6.2+ or avoid using problematic types with deeply nested generics.
error Cannot find module 'type-plus' or its corresponding type declarations
cause Missing or incorrect TypeScript version (<5.4) or package not installed.
fix
Install package: npm install type-plus@latest. Ensure TypeScript >=5.4 for v8.0.0+.
error Property 'IsAny' does not exist on type 'typeof import("type-plus")'
cause Incorrect import style: using `require` or wrong path.
fix
Use proper ES import: import { IsAny } from 'type-plus'.
breaking v8.0.0 renames many types: e.g., `Equal` to `$Equal`, `case*` to `$*`, `Exact` options restructured.
fix Upgrade migration: replace old names with new ones (see changelog).
deprecated `NoInfer` and `Failed` types are deprecated in v8.0.0-beta.
fix Remove usage or use alternative types recommended in documentation.
gotcha Incorrect usage of `typesVersions` in package.json caused resolution issues in v8.0.0-beta.5.
fix Update to version 8.0.0-beta.6 or later.
gotcha TypeScript 5.4+ required from v8.0.0-beta.2 onward; earlier versions may fail to load types.
fix Ensure TypeScript version is >=5.4.
gotcha Excessive stack depth errors for some types like `Zeros` in earlier versions.
fix Upgrade to v7.6.2 or later for fix.
npm install type-plus
yarn add type-plus
pnpm add type-plus

Demonstrates basic type-level type guards and array reversal using type-plus in TypeScript.

import { IsAny, IsNever, IsLiteral, IsUnion, Exact, A } from 'type-plus'

// Check types at the type level
type CheckAny = IsAny<any> // true
type CheckNever = IsNever<never> // true
type CheckLiteral = IsLiteral<'hello'> // true
type CheckUnion = IsUnion<string | number> // true

// Exact type comparison
type ExactCheck = Exact<{ a: 1 }, { a: 1 }> // true
type ExactMismatch = Exact<{ a: 1 }, { a: 2 }> // false

// Array utilities
type Reversed = A.Reverse<[1, 2, 3]> // [3, 2, 1]