Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: 21 days ago
JSON representation
🔩 The missing TypeScript utils
- Host: GitHub
- URL: https://github.com/garronej/tsafe
- Owner: garronej
- License: mit
- Created: 2021-03-29T19:49:47.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-02T11:30:57.000Z (about 1 month ago)
- Last Synced: 2024-10-03T10:12:21.356Z (about 1 month ago)
- Topics: deno, hacktoberfest, node, npm, testing, type-safety, typescript, utilities
- Language: TypeScript
- Homepage: https://docs.tsafe.dev
- Size: 31.4 MB
- Stars: 408
- Watchers: 4
- Forks: 6
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A collection of utilities to take your TypeScript development up a notch
(you can cherrypick what you import)
## A few GIFs to convince you that you need `tsafe` in your life
Assert things you know are true, get runtime errors where you were wrong:
Implement compile time unit testing
Playground
Make sure all properties of an object are deconstructed
Playground
Make sure you never forget a case in a switch
Playground
Make TypeScript believe whatever you say without having to writeconst obj2 = obj as Bar
.
The more powerfully is to be able to tell TypeScript thatobj
ist not of typeBar
:
Make sure your zod schema exactly matches a given type:
## 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 corrects frustrating aspects of default utility types such as [`ReturnType`](https://docs.tsafe.dev/returntype).[**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, typeGuard, ... } from "https://deno.land/x/tsafe/mod.ts";
```## Install elsewhere:
```bash
$ npm install --save tsafe
#OR
$ yarn add tsafe
```