Registry / type-stubs / tsafe
library1.8.12jsnpmunverified

A collection of utility functions and type helpers for TypeScript, currently at version 1.8.12. Released frequently (multiple releases in 2024). Provides runtime functions like assert and assertDeepEqual, along with type-level utilities such as Equals, EqualsT, ReturnType of, UnpackPromise, Assert, Id, etc. No runtime dependencies. Tree-shakable and supports Deno. Differentiates by offering TypeScript utility types that require runtime implementations (e.g., assertion functions), complementing the standard library.

npm install tsafe
INSTALL
IMPORT
SIG · TSAFE
T
tsafe
type-stubsjavascriptv1.8.12
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

assert
import { assert } from 'tsafe'
const assert = require('tsafe').assert
ESM-only; named export.
Equals
import { type Equals } from 'tsafe'
import { Equals } from 'tsafe'
Equals is a type-only export; use 'import type' for clarity.
ReturnType of
import { ReturnTypeOf } from 'tsafe'
import { ReturnTypeof } from 'tsafe'
Case-sensitive export name.

Shows importing and using assert, assertDeepEqual, and the Equals type helper in TypeScript.

import { assert, assertDeepEqual, type Equals } from 'tsafe'; // Type-level equality check (compile time) type Check = Equals<{ a: string }, { a: string }>; // true // Runtime assertion with type narrowing function greet(input: unknown) { assert(typeof input === 'string', 'Expected string'); console.log(input.toUpperCase()); // TypeScript knows input is string } // Deep equality check for objects assertDeepEqual({ x: 1, y: 2 }, { y: 2, x: 1 }); // passes // Exhaustive switch helper function handleShape(s: 'circle' | 'square') { switch (s) { case 'circle': return 'round'; case 'square': return 'corners'; default: return assert(false, 'Unhandled shape'); // never reached } }
Debug
Known issues
breakingVersion 0.x to 1.x changed export structure; assert moved from 'tsafe/assert' to 'tsafe'.
fix
Update imports to import from 'tsafe' directly.
affects: <1.0
deprecatedThe 'Equiv' type was deprecated in v1.5 in favor of 'Equals'.
fix
Replace 'Equiv' with 'Equals'.
affects: >=1.5
gotchaassert function throws on false, not just narrows type. Do not use for branching logic without try-catch.
fix
Use user-defined type guards or if statements for branching.
affects: >=1.0
breakingIn v1.8.0, 'assertDeepEqual' was added; previous deep equality check required manual comparison.
fix
Upgrade to use built-in deep equality.
affects: <1.8.0
Errors
Common errors & fixes
TypeError: tsafe_1.assert is not a function
Attempting to use CommonJS require with tsafe which is ESM-only
fix
Use ES module import syntax: import { assert } from 'tsafe';
Module '"node_modules/tsafe/index"' has no exported member 'ReturnTypeOf'. Did you mean to use 'import ReturnTypeOf from "tsafe"'? (ts2305)
Case-sensitive export name 'ReturnTypeOf'
fix
Correct the import: import { ReturnTypeOf } from 'tsafe'; (capitalization matters)
This expression is not callable. Type 'never' has no call signatures.
Using assert in a function with return type never incorrectly
fix
Ensure assert is called with a boolean expression that narrows correctly; consider using assert as a type guard with a custom message.
Upgrade
Version history
1.8.12latest on npm
Audit
Dependencies
typescriptoptionalTypeScript is a peer dependency for type definitions
Agent activity
20 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
tsafe — npm install tsafe · libregistry