Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/LeDDGroup/typescript-conditional-types
Helpers for typescript generic types
https://github.com/LeDDGroup/typescript-conditional-types
typescript
Last synced: about 2 months ago
JSON representation
Helpers for typescript generic types
- Host: GitHub
- URL: https://github.com/LeDDGroup/typescript-conditional-types
- Owner: LeDDGroup
- License: mit
- Created: 2018-12-21T16:09:27.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-13T22:00:32.000Z (over 4 years ago)
- Last Synced: 2024-08-02T05:12:05.346Z (5 months ago)
- Topics: typescript
- Language: TypeScript
- Size: 31.3 KB
- Stars: 50
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# typescript-conditional-types
[![npm version](https://img.shields.io/npm/v/typescript-conditional-types.svg)](https://www.npmjs.com/package/typescript-conditional-types)
[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)Helpers for typescript generic types
**Table of Contents**
- [Motivation](#motivation)
- [Install](#install)
- [Type Helper List](#type-helper-list)
- [Usage Example](#usage-example)## Motivation
Creating complex types with conditional types ( `T extends U ? X : Y` ) could be a little verbose. This package aims to simplify code and make it more readable.
## Install
```bash
$ npm install typescript-conditional-types
```You'll probably want to save it in the _devDependencies_
## Type Helper List
- _If_: If _Condition_ is `true` resulting type is _Then_ else _Else_
- _And_: `true` if _A_ and _B_ are both `true` else `false`
- _Or_: `true` if _A_ or _B_ are `true` else `false`
- _Not_: Negate _A_
- _Extends_: `true` if _A_ extends _B_ like in `A extends B ? true : false`
- _Extends, Then, Else>`## Usage Example
```ts
import { If } from "typescript-conditional-types";type BooleanToString = If
BooleanToString // "true"
BooleanToString // "false"
```