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
muslnode 18–223 runs
build_error
glibcnode 18–223 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
}
}
Errors
Common errors & fixes
TypeError: tsafe_1.assert is not a function
Attempting to use CommonJS require with tsafe which is ESM-only
fixUse 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'
fixCorrect 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
fixEnsure assert is called with a boolean expression that narrows correctly; consider using assert as a type guard with a custom message.
Audit
Dependencies
typescriptoptionalTypeScript is a peer dependency for type definitions