Skip to main content

A collection of utilities to step up your TypeScript game


Three GIFs to convince you that you need tsafe in your life

Assert thing you know are true, get runtime error if you where wrong:

Test the type definitions of your APIs:

Make TypeScript believe whatever you say:


Powerful TypeScript features like assertion functions or user-defined type guards are only useful if paired with utility functions.

TypeScript, however, only exports type helpers (e.g. Record, ReturnType, etc.).

This module provides «the missing builtins» such as the assert function and corrects frustrating aspects of default utility type such as ReturnType.

Documentation website


tsafe is both an NPM and a Deno module. (Achieved with denoify)

Import in deno:

import { assert, typeGuard, ... } from "";

Install elsewhere:

$ npm install --save tsafe
$ yarn add tsafe