Skip to content

garronej/tsafe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

408 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image

A collection of utilities to take your TypeScript development up a notch

Image Image Image Image
Image This module is tree shakable

Documentation



Make sure two types are identical

Image
Image
Playground


A assertion function that typescript understands

Image



Make sure your zod schema exactly matches a given type:
Image
Playground



Make sure you never forget a case in a switch

Image
Playground



Make TypeScript believe whatever you say without having to write const obj2 = obj as Bar.
The more powerfully is to be able to tell TypeScript that obj ist not of type Bar:

Image

Motivations

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 other utilities that cannot be just type helpers.

Documentation website

Installation

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

Import in deno:

import { assert, type Equals, ... } from "https://deno.land/x/tsafe/mod.ts";

Install elsewhere:

$ npm install --save tsafe