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: 2 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-11-18T19:58:37.000Z (25 days ago)
- Last Synced: 2024-12-05T10:04:07.556Z (9 days ago)
- Topics: deno, hacktoberfest, node, npm, testing, type-safety, typescript, utilities
- Language: TypeScript
- Homepage: https://docs.tsafe.dev
- Size: 35.3 MB
- Stars: 432
- Watchers: 4
- Forks: 7
- Open Issues: 7
-
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 cherry-pick what you import
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 writeconst obj2 = obj as Bar
.
The more powerfully is to be able to tell TypeScript thatobj
ist not of typeBar
:
## 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
```