Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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

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"
```