https://github.com/LeDDGroup/typescript-conditional-types
Helpers for typescript generic types
https://github.com/LeDDGroup/typescript-conditional-types
typescript
Last synced: about 1 year 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 (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-07-13T22:00:32.000Z (almost 6 years ago)
- Last Synced: 2025-04-07T05:33:13.368Z (about 1 year ago)
- Topics: typescript
- Language: TypeScript
- Size: 31.3 KB
- Stars: 50
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# typescript-conditional-types
[](https://www.npmjs.com/package/typescript-conditional-types)
[](https://conventionalcommits.org)
[](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"
```