typescript-conditional-types
Helpers for typescript generic types
Last updated 3 years ago by danielpanpm .
MIT · Original npm · Tarball · package.json
$ cnpm install typescript-conditional-types 
SYNC missed versions from official npm registry.

typescript-conditional-types

npm version Conventional Commits code style: prettier

Helpers for typescript generic types

Table of Contents

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.

Instead of

type ComplexType<A> = A extends boolean
  ? number
  : A extends number ? number : string
  : string

You could write

type ComplexType<A> = If<
  Or<Extends<A, number>, Extends<A, boolean>>,
  number,
  string
>;

Install

$ npm install typescript-conditional-types

You'll probably want to save it in the devDependencies

Type Helper List

Usage Example

import { If } from "typescript-conditional-types";

type BooleanToString<T extends boolean> = If<T, "true", "false">

BooleanToString<true> // "true"
BooleanToString<false> // "false"

Current Tags

  • 1.0.0                                ...           latest (3 years ago)

1 Versions

  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 9
Last Day 0
Last Week 1
Last Month 0
Dependencies (0)
None
Dev Dependencies (7)
Dependents (1)

Copyright 2014 - 2021 © npmmirror.com |