# type-zoo

> A menagerie of useful type operators for TypeScript

Latest version **3.4.1** (published 2019-08-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install type-zoo
pnpm add type-zoo
yarn add type-zoo
bun add type-zoo
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.4.1 |
| Published | 2019-08-08 |
| First published | 2017-11-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 498 |
| Author | Tom Crockett |
| Maintainers | pelotom |

## Links

- npm: https://www.npmjs.com/package/type-zoo
- Repository: https://github.com/pelotom/type-zoo
- npm.io page: https://npm.io/package/type-zoo

## Recent versions

- 3.4.1 (latest) — 2019-08-08
- 3.4.0 — 2019-07-19
- 3.3.0 — 2019-01-07
- 3.2.1 — 2018-11-06
- 3.1.1 — 2018-08-22
- 3.1.0 — 2018-07-10
- 3.0.0 — 2018-06-26
- 2.0.0 — 2018-04-23
- 1.2.1 — 2018-01-29
- 1.1.1 — 2018-01-19
- 1.1.0 — 2018-01-17
- 1.0.1 — 2017-12-21
- 1.0.0 — 2017-11-29
- 0.0.1 — 2017-11-28

## README

# Type Zoo [![Build Status](https://travis-ci.org/pelotom/type-zoo.svg?branch=master)](https://travis-ci.org/pelotom/type-zoo)

TypeScript ships with some handy user-definable type operators: `Partial`, `Readonly`, `Pick` and `Record`. However many other useful operators have been demonstrated in GitHub issue comments and elsewhere. This repository is intended to collect all this folklore in one place, so you can stop copying and pasting these solutions into project after project.

PRs more than welcome! Please note that this library is intended to be fully static, i.e. it has no runtime component, only a type definition file. The idea is that these could all potentially make their way into `lib.d.ts` at some point.

## Installation

```
yarn add type-zoo
```

## API

---

### `ExcludeStrict<T, U extends T>`

Exclude from `T` those types that are assignable to `U`, where `U` must exist in `T`.

Similar to `Exclude` but requires the exclusion list to be composed of valid members of `T`.

See: https://github.com/pelotom/type-zoo/issues/37

---

### `ExtractStrict<T, U extends T>`

Extract from `T` those types that are assignable to `U`, where `U` must exist in `T`.

Similar to `Extract` but requires the extraction list to be composed of valid members of `T`.

See: https://github.com/pelotom/type-zoo/issues/37

---

### `NoInfer<T>`

Use to prevent a usage of type `T` from being inferred in other generics.

Example:

```ts
declare function assertEqual<T>(actual: T, expected: NoInfer<T>): boolean;
```

Type `T` will now only be inferred based on the type of the `actual` param, and
the `expected` param is required to be assignable to the type of `actual`.
This allows you to give one particular usage of type `T` full control over how the
compiler infers type `T`.

See: https://github.com/Microsoft/TypeScript/issues/14829#issuecomment-322267089

---

### `Omit<T, K extends keyof any>`

Drop keys `K` from `T` if they are present.

See: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-377567046

---

### `OmitStrict<T, K extends keyof T>`

Drop keys `K` from `T`, where `K` must exist in `T`.

See: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-377567046

---

### `Overwrite<T, U>`

Like `T & U`, but where there are overlapping properties using the type from `U` only.

See: https://github.com/pelotom/type-zoo/pull/14#discussion_r183527882

---

### `Param#<T extends Function>` and `ParamTypes<T extends Function>`

These helpers extract the Parameter-types from Functions.

See: https://github.com/pelotom/type-zoo/issues/22

---

### `Pick#<T, K1 in keyof T, K2 in ...>`

Like `Pick<>` but for `#` of nested levels!

See https://gist.github.com/staltz/368866ea6b8a167fbdac58cddf79c1bf

---

### `Public#<T>`

Get only the public members of a type or class. When applied to a class T with private members, Public<T> can be implemented.

See https://github.com/Microsoft/TypeScript/issues/18499#issuecomment-429272545

## Related Projects

[`typelevel-ts`](https://github.com/gcanti/typelevel-ts) and [`typical`](https://github.com/tycho01/typical) are two projects with similar goals to this one. The main difference is that those libraries are more focused on advanced type-level computation, whereas Type Zoo is meant to capture more basic type operators which have been proposed as candidates for inclusion in `lib.d.ts`, or even as first-class language primitives. The idea is that these types will hopefully make their way into the language proper, at which point you can simply stop importing them from `type-zoo` and be on your merry way.

---
_Source: https://npm.io/package/type-zoo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
