Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/garronej/tsafe

🔩 The missing TypeScript utils
https://github.com/garronej/tsafe

deno hacktoberfest node npm testing type-safety typescript utilities

Last synced: 2 days ago
JSON representation

🔩 The missing TypeScript utils

Awesome Lists containing this project

README

        





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





















You can cherry-pick what you import



Documentation






Make sure two types are identical










Playground





A assertion function that typescript understands











Make sure your zod schema exactly matches a given type:





Playground







Make sure you never forget a case in a switch







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:





## Motivations

Powerful TypeScript features like [assertion functions](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions) or [user-defined type guards](https://www.typescriptlang.org/docs/handbook/advanced-types.html#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](https://docs.tsafe.dev/assert) and other utilities that cannot be just type helpers.

[**Documentation website**](https://docs.tsafe.dev)

## Installation

`tsafe` is both an [NPM](https://www.npmjs.com/package/tsafe) and a [Deno](https://deno.land/x/tsafe) module.
(Achieved with [denoify](https://github.com/garronej/denoify))

## Import in deno:

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

## Install elsewhere:

```bash
$ npm install --save tsafe
```