{"id":22481,"library":"tsafe","title":"tsafe","description":"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.","status":"active","version":"1.8.12","language":"javascript","source_language":"en","source_url":"git://github.com/garronej/tsafe","tags":["javascript","typescript"],"install":[{"cmd":"npm install tsafe","lang":"bash","label":"npm"},{"cmd":"yarn add tsafe","lang":"bash","label":"yarn"},{"cmd":"pnpm add tsafe","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"TypeScript is a peer dependency for type definitions","package":"typescript","optional":true}],"imports":[{"note":"ESM-only; named export.","wrong":"const assert = require('tsafe').assert","symbol":"assert","correct":"import { assert } from 'tsafe'"},{"note":"Equals is a type-only export; use 'import type' for clarity.","wrong":"import { Equals } from 'tsafe'","symbol":"Equals","correct":"import { type Equals } from 'tsafe'"},{"note":"Case-sensitive export name.","wrong":"import { ReturnTypeof } from 'tsafe'","symbol":"ReturnType of","correct":"import { ReturnTypeOf } from 'tsafe'"}],"quickstart":{"code":"import { assert, assertDeepEqual, type Equals } from 'tsafe';\n\n// Type-level equality check (compile time)\ntype Check = Equals<{ a: string }, { a: string }>; // true\n\n// Runtime assertion with type narrowing\nfunction greet(input: unknown) {\n  assert(typeof input === 'string', 'Expected string');\n  console.log(input.toUpperCase()); // TypeScript knows input is string\n}\n\n// Deep equality check for objects\nassertDeepEqual({ x: 1, y: 2 }, { y: 2, x: 1 }); // passes\n\n// Exhaustive switch helper\nfunction handleShape(s: 'circle' | 'square') {\n  switch (s) {\n    case 'circle': return 'round';\n    case 'square': return 'corners';\n    default: return assert(false, 'Unhandled shape'); // never reached\n  }\n}","lang":"typescript","description":"Shows importing and using assert, assertDeepEqual, and the Equals type helper in TypeScript."},"warnings":[{"fix":"Update imports to import from 'tsafe' directly.","message":"Version 0.x to 1.x changed export structure; assert moved from 'tsafe/assert' to 'tsafe'.","severity":"breaking","affected_versions":"<1.0"},{"fix":"Replace 'Equiv' with 'Equals'.","message":"The 'Equiv' type was deprecated in v1.5 in favor of 'Equals'.","severity":"deprecated","affected_versions":">=1.5"},{"fix":"Use user-defined type guards or if statements for branching.","message":"assert function throws on false, not just narrows type. Do not use for branching logic without try-catch.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Upgrade to use built-in deep equality.","message":"In v1.8.0, 'assertDeepEqual' was added; previous deep equality check required manual comparison.","severity":"breaking","affected_versions":"<1.8.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use ES module import syntax: import { assert } from 'tsafe';","cause":"Attempting to use CommonJS require with tsafe which is ESM-only","error":"TypeError: tsafe_1.assert is not a function"},{"fix":"Correct the import: import { ReturnTypeOf } from 'tsafe'; (capitalization matters)","cause":"Case-sensitive export name 'ReturnTypeOf'","error":"Module '\"node_modules/tsafe/index\"' has no exported member 'ReturnTypeOf'. Did you mean to use 'import ReturnTypeOf from \"tsafe\"'? (ts2305)"},{"fix":"Ensure assert is called with a boolean expression that narrows correctly; consider using assert as a type guard with a custom message.","cause":"Using assert in a function with return type never incorrectly","error":"This expression is not callable. Type 'never' has no call signatures."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}