Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ts-essentials/ts-essentials
All essential TypeScript types in one place 🤙
https://github.com/ts-essentials/ts-essentials
essentials toolbox type-level-programming types typescript
Last synced: 4 days ago
JSON representation
All essential TypeScript types in one place 🤙
- Host: GitHub
- URL: https://github.com/ts-essentials/ts-essentials
- Owner: ts-essentials
- License: mit
- Created: 2018-09-15T23:46:19.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-11-17T22:15:11.000Z (25 days ago)
- Last Synced: 2024-11-30T00:46:00.680Z (13 days ago)
- Topics: essentials, toolbox, type-level-programming, types, typescript
- Language: TypeScript
- Homepage:
- Size: 731 KB
- Stars: 3,786
- Watchers: 13
- Forks: 121
- Open Issues: 28
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- my-awesome-list - ts-essentials - essentials | 3793 | (TypeScript)
- awesome-github-star - ts-essentials - essentials | 3341 | (TypeScript)
- awesome-angular - ts-essentials - All essential TypeScript types in one place. (Table of contents / Third Party Components)
- jimsghstars - ts-essentials/ts-essentials - All essential TypeScript types in one place 🤙 (TypeScript)
- fucking-awesome-angular - ts-essentials - All essential TypeScript types in one place. (Table of contents / Third Party Components)
- stars - ts-essentials - essentials | 3795 | (TypeScript)
- stars - ts-essentials - essentials | 3795 | (TypeScript)
README
ts-essentials
All essential TypeScript types in one place 🤙
## Install
```sh
npm install --save-dev ts-essentials
```👉 We require `typescript>=4.5`. If you're looking for support for older TS versions, please have a look at the
[TypeScript dependency table](https://github.com/ts-essentials/ts-essentials/tree/master#TypeScript-dependency-table)👉 As we really want types to be stricter, we require enabled
[strictNullChecks](https://www.typescriptlang.org/tsconfig#strictNullChecks) in your project## API
`ts-essentials` is a set of high-quality, useful TypeScript types that make writing type-safe code easier.
### Basic
- [`Builtin`](/lib/built-in) - Matches primitive, function, date, error or regular expression
- [`KeyofBase`](/lib/key-of-base) -
[`keyofStringsOnly`](https://www.typescriptlang.org/tsconfig#keyofStringsOnly)-tolerant analogue for `PropertyKey`
- [`Prettify`](/lib/prettify/) - flattens type and makes it more readable on the hover in your IDE
- [`Primitive`](/lib/primitive) - Matches any
[primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive)
- [`StrictExclude`](/lib/strict-exclude) - Constructs a type by excluding from `UnionType`
all union members that are assignable to `ExcludedMembers`. This is stricter version of
[`Exclude`](https://www.typescriptlang.org/docs/handbook/utility-types.html#excludeuniontype-excludedmembers)
- [`StrictExtract`](/lib/strict-extract) - Constructs a type by extracting from `Type` all union members
that are assignable to `Union`. This is stricter version of
[`Extract`](https://www.typescriptlang.org/docs/handbook/utility-types.html#extracttype-union)
- [`StrictOmit`](/lib/strict-omit) - Constructs a type by picking all properties from `Type` and then
removing `Keys`. This is stricter version of
[`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys)
- [`Writable`](/lib/writable) - Constructs a type with removed `readonly` for all properties of `Type`, meaning
the properties of the constructed type can be reassigned### Utility types
- [`AsyncOrSync`](/lib/async-or-sync) - Constructs a type with `Type` or `PromiseLike`
- [`AsyncOrSyncType`](/lib/async-or-sync-type) - Unwraps `AsyncOrSync` type
- [`Dictionary`](/lib/dictionary) - Constructs a required object type which property keys are `Keys`
(`string` by default) and which property values are `Type`
- [`Merge`](/lib/merge) - Constructs a type by picking all properties from `Object1` and `Object2`.
Property values from `Object2` override property values from `Object1` when property keys are the same
- [`MergeN`](/lib/merge-n) - Constructs a type by merging objects with type `Merge` in tuple `Tuple` recursively
- [`Newable`](/lib/newable) - Constructs a class type with constructor which has return type `ReturnType`
- [`NonNever`](/lib/non-never) - Constructs a type by picking all properties from type `Type` which values don't
equal to `never`
- [`OmitProperties`](/lib/omit-properties) - Constructs a type by picking all properties from type `Type`
and removing those properties which values equal to `Value`
- [`Opaque`](/lib/opaque) - Constructs a type which is a subset of `Type` with a specified unique token
`Token`
- [`PathValue`](/lib/path-value) - Constructs a path value for type `Type` and path `Path`
- [`Paths`](/lib/paths) - Constructs a union type by picking all possible paths for type `Type`
- [`PickProperties`](/lib/pick-properties) - Constructs a type by picking all properties from type `Type`
which values equal to `Value`
- [`SafeDictionary`](/lib/safe-dictionary) - Constructs an optional object type which property keys are
`Keys` (`string` by default) and which property values are `Type`
- [`UnionToIntersection`](/lib/union-to-intersection) - Constructs a intersection type from union type `Union`
- [`ValueOf`](/lib/value-of) - Constructs a type for type `Type` and equals to a primitive for primitives, array
elements for arrays, function return type for functions or object property values for objects
- [`XOR`](/lib/xor) - Construct a type which is assignable to either type `Type1`,
`Type2` but not both. Starting in ts-essentials@10, it supports up to 50 generic types.### Mark wrapper types
- [`MarkOptional`](/lib/mark-optional) - Constructs a type by picking all properties from type `Type` where
properties `Keys` are set as optional, meaning they aren't required
- [`MarkReadonly`](/lib/mark-readonly) - Constructs a type by picking all properties from type `Type` where
properties `Keys` are set to `readonly`, meaning they cannot be reassigned
- [`MarkRequired`](/lib/mark-required) - Constructs a type by picking all properties from type `Type` where
properties `Keys` are set as required
- [`MarkWritable`](/lib/mark-writable) - Constructs a type by picking all properties from type `Type` where
properties `Keys` remove `readonly` modifier, meaning they can be reassigned### Deep wrapper types
- [`Buildable`](/lib/buildable) - Constructs a type by combining `DeepPartial` and `DeepWritable`, meaning all
properties from type `Type` are recursively set as non-`readonly` and optional, meaning they can be reassigned and
aren't required
- [`DeepNonNullable`](/lib/deep-non-nullable) - Constructs a type by picking all properties from type `Type`
recursively and exclude `null` and `undefined` property values from all of them. To make properties non-nullable on
one level, use [`NonNullable`](https://www.typescriptlang.org/docs/handbook/utility-types.html#nonnullabletype)
- [`DeepNullable`](/lib/deep-nullable) - Constructs a type by picking all properties from type `Type` recursively
and include `null` property values for all of them
- [`DeepOmit`](/lib/deep-omit) - Constructs a type by picking all properties from type `Type` and removing
properties which values are `never` or `true` in type `Filter`. If you'd like type `Filter` to be validated against a
structure of `Type`, please use [`StrictDeepOmit`](./lib/strict-deep-omit/).
- [`DeepPartial`](/lib/deep-partial) - Constructs a type by picking all properties from type `Type` recursively
and setting them as optional, meaning they aren't required. To make properties optional on one level, use
[`Partial`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype)
- [`DeepPick`](/lib/deep-pick) - Constructs a type by picking set of properties, which have property
values `never` or `true` in type `Filter`, from type `Type`. If you'd like type `Filter` to be validated against a
structure of `Type`, please use [`StrictDeepPick`](./lib/strict-deep-pick/).
- [`DeepReadonly`](/lib/deep-readonly) - Constructs a type by picking all properties from type `Type` recursively
and setting `readonly` modifier, meaning they cannot be reassigned. To make properties `readonly` on one level, use
[`Readonly`](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype)
- [`DeepRequired`](/lib/deep-required) - Constructs a type by picking all properties from type `Type` recursively
and setting as required. To make properties required on one level, use
[`Required`](https://www.typescriptlang.org/docs/handbook/utility-types.html#requiredtype)
- [`DeepUndefinable`](/lib/deep-undefinable) - Constructs a type by picking all properties from type `Type`
recursively and include `undefined` property values for all of them
- [`DeepWritable`](/lib/deep-writable) - Constructs a type by picking all properties from type `Type` recursively
and removing `readonly` modifier, meaning they can be reassigned. To make properties writable on one level, use
`Writable`
- [`StrictDeepOmit`](/lib/strict-deep-omit) - Constructs a type by picking all properties from type `Type`
and removing properties which values are `never` or `true` in type `Filter`. The type `Filter` is validated against a
structure of `Type`.
- [`StrictDeepPick`](/lib/strict-deep-pick) - Constructs a type by picking set of properties, which have
property values `never` or `true` in type `Filter`, from type `Type`. The type `Filter` is validated against a
structure of `Type`.### Key types
- [`OptionalKeys`](/lib/optional-keys) - Constructs a union type by picking all optional properties of object type
`Type`
- [`PickKeys`](/lib/pick-keys) - Constructs a union type by picking all properties of object type `Type`
which values are assignable to type `Value`
- [`ReadonlyKeys`](/lib/readonly-keys) - Constructs a union type by picking all `readonly` properties of object
type `Type`, meaning their values cannot be reassigned
- [`RequiredKeys`](/lib/required-keys) - Constructs a union type by picking all required properties of object type
`Type`
- [`WritableKeys`](/lib/writable-keys) - Constructs a union type by picking all writable properties of object type
`Type`, meaning their values can be reassigned### Type checkers
- [`Exact`](/lib/exact) - Returns `Type` when type `Type` and `Shape` are identical. Otherwise returns
`never`
- [`IsAny`](/lib/is-any) - Returns `true` when type `Type` is `any`. Otherwise returns `false`
- [`IsNever`](/lib/is-never) - Returns `true` when type `Type` is `never`. Otherwise returns `false`
- [`IsUnknown`](/lib/is-unknown) - Returns `true` when type `Type` is `unknown`. Otherwise returns `false`
- [`IsTuple`](/lib/is-tuple) - Returns `Type` when type `Type` is tuple. Otherwise returns `never`
- [`NonEmptyObject`](/lib/non-empty-object) - Returns `Object` when `Object` has at least one key. Otherwise
returns `never`### Arrays and Tuples
- [`AnyArray`](/lib/any-array) - Matches `Array` or `ReadonlyArray` (`Type` is `any` by default)
- [`ArrayOrSingle`](/lib/array-or-single) - Matches `Type` or `Type[]`
- [`ElementOf`](/lib/element-of) - Constructs a type which equals to array element type for type `Type`
- [`Head`](/lib/head) - Constructs a type which equals to first element in type `Type`
- [`NonEmptyArray`](/lib/non-empty-array) - Matches array with at least one element of type `Type`
- [`ReadonlyArrayOrSingle`](/lib/readonly-array-or-single) - Matches `Type` or `readonly Type[]`
- [`Tail`](/lib/tail) - Constructs a type which equals to elements but first one in type `Type`
- [`Tuple`](/lib/tuple) - Matches type constraint for tuple with elements of type `Type` (`any` by default)### Change case
- [`CamelCase`](/lib/camel-case) - Converts type `Type` to camel case (e.g. `camelCase`)
- [`DeepCamelCaseProperties`](/lib/deep-camel-case-properties) - Constructs a type by picking all properties from
type `Type` recursively and converting all of them to camel case### Function types
- [`AnyFunction`](/lib/any-function) - Matches function type with arguments type `Args` (`any[]` by
default) and return type `ReturnType` (`any` by default)
- [`PredicateFunction`](/lib/predicate-function) - Matches type constraint for type guard, meaning first argument is
used in return type and return type is
[type predicate](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates)
- [`PredicateType`](/lib/predicate-type) - Constructs a type which equals to narrowed type in predicate function
`Type`### Utility functions
⚠️ Make sure you add `ts-essentials` to your `dependencies` (`npm install --save ts-essentials`) to avoid runtime errors
- [`new UnreachableCaseError(value)`](/lib/functions/unreachable-case-error) - Matches runtime class instance type that
helps check exhaustiveness for `value`. When `value` isn't `never`, it shows TypeScript error
- [`assert(condition, message?)`](/lib/functions/assert) - Matches runtime function that helps assert `condition`. When
`condition` is falsy, it throws an error with `Assertion Error: ${message}` (message is
`"no additional info provided"` by default)
- [`createFactoryWithConstraint()(value)`](/lib/functions/create-factory-with-constraint) - Matches runtime
function, which validates that type of `value` matches `Constraint` without changing resulting type of `value`.
Ponyfill for
[`satisfies` operator](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-9.html#the-satisfies-operator)
- [`isExact()(actual)`](/lib/functions/is-exact) - Matches runtime function, which validates that type of
`actual` equals to `Expected`. Otherwise shows TypeScript error
- [`noop(..._args)`](/lib/functions/noop) - Matches runtime function that does nothing with arguments `_args`## Search
When one of utility types is known by a different name, kindly ask adding it here for the better search.
- `ArrayValues` - [`ValueOf`](/lib/value-of)
- `Branded` - [`Opaque`](/lib/opaque)
- `ConditionalKeys` - [`PickKeys`](/lib/pick-keys)
- `Except` - [`StrictOmit`](/lib/strict-omit)
- `Get` - [`PathValue`](/lib/path-value)
- `Mutable` - [`Writable`](/lib/writable)
- `Nominal` - [`Opaque`](/lib/opaque)
- `Set*`, e.g. `SetOptional` - `Mark*`, e.g. [`MarkReadonly`](/lib/mark-readonly)
- `Unwrap` - [`Prettify`](/lib/prettify/)
- `ValueOf` - `DictionaryValues`## Built-in types
TypeScript provides several [utility types](https://www.typescriptlang.org/docs/handbook/utility-types.html) to
facilitate common type transformations. These utilities are available globally.- [`Awaited`](https://www.typescriptlang.org/docs/handbook/utility-types.html#awaitedtype) - This type is meant to
model operations like `await` in `async` functions, or the `.then()` method on `Promise`s - specifically, the way that
they recursively unwrap `Promise`s
- [`Capitalize`](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#capitalizestringtype) -
Converts the first character in the string to an uppercase equivalent
- [`ConstructParameters`](https://www.typescriptlang.org/docs/handbook/utility-types.html#constructorparameterstype) -
Constructs a tuple or array type from the types of a constructor function type `Type`
- [`Exclude`](https://www.typescriptlang.org/docs/handbook/utility-types.html#excludeuniontype-excludedmembers) -
Constructs a type by excluding from `UnionType` all union members that are assignable to `ExcludedMembers`
- [`Extract`](https://www.typescriptlang.org/docs/handbook/utility-types.html#extracttype-union) -
Constructs a type by extracting from `Type` all union members that are assignable to `Union`
- [`InstanceType`](https://www.typescriptlang.org/docs/handbook/utility-types.html#instancetypetype) - Constructs
a type consisting of the instance type of a constructor function in `Type`
- [`Lowercase`](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#lowercasestringtype) -
Converts each character in the string to the lowercase equivalent
- [`NonNullable`](https://www.typescriptlang.org/docs/handbook/utility-types.html#nonnullabletype) - Constructs a
type by excluding null and undefined from `Type`
- [`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys) - Constructs a
type by picking all properties from `Type` and then removing `Keys`
- [`Parameters`](https://www.typescriptlang.org/docs/handbook/utility-types.html#parameterstype) - Constructs a
tuple type from the types used in the parameters of a function type `Type`
- [`Partial`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype) - Constructs a type
with all properties of `Type` set to optional
- [`Pick`](https://www.typescriptlang.org/docs/handbook/utility-types.html#picktype-keys) - Constructs a
type by picking the set of properties `Keys` from `Type`
- [`Readonly`](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype) - Constructs a type
with all properties of `Type` set to `readonly`, meaning the properties of the constructed type cannot be reassigned
- [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type) - Constructs
an object type whose property keys are `Keys` and whose property values are `Type`
- [`Required`](https://www.typescriptlang.org/docs/handbook/utility-types.html#requiredtype) - Constructs a type
consisting of all properties of `Type` set to required
- [`ReturnType`](https://www.typescriptlang.org/docs/handbook/utility-types.html#returntypetype) - Constructs a
type consisting of the return type of function type `Type` parameter
- [`Uncapitalize`](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#uncapitalizestringtype) -
Converts the first character in the string to a lowercase equivalent
- [`Uppercase`](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html#uppercasestringtype) -
Converts each character in the string to the uppercase version## TypeScript dependency table
| `ts-essentials` | `typescript` / type of dependency |
| --------------- | ------------------------------------------------------------------------------------- |
| `^10.0.0` | `^4.5.0` / [peer optional](https://github.com/ts-essentials/ts-essentials/issues/370) |
| `^9.4.0` | `^4.1.0` / [peer optional](https://github.com/ts-essentials/ts-essentials/issues/370) |
| `^8.0.0` | `^4.1.0` / peer |
| `^5.0.0` | `^3.7.0` / peer |
| `^3.0.1` | `^3.5.0` / peer |
| `^1.0.1` | `^3.2.2` / dev |
| `^1.0.0` | `^3.0.3` / dev |## Contributors
Special shout-out to active contributors:
- [Kris Kaczor](https://x.com/krzkaczor) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=krzkaczor)
- [Xiao Liang](https://scholar.google.com/citations?user=3xZtvpAAAAAJ) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=yxliang01)
- [Mateusz Burzyński](https://x.com/AndaristRake) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=Andarist)
- [Artur Kozak](https://x.com/quezak2) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=quezak)
- [Zihua Wu](https://x.com/gabriel_wzh) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=lucifer1004)
- [Alexey Berezin](https://x.com/beraliv) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=Beraliv)
- [Som Shekhar Mukherjee](https://github.com/som-sm) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=som-sm)And thanks goes to these wonderful people:
- [Maciej Bembenista](https://github.com/macbem) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=macbem)
- [Michael Tontchev](https://www.linkedin.com/in/michael-tontchev-7956a269/) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=MichaelTontchev)
- [Thomas den Hollander](https://github.com/ThomasdenH) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=ThomasdenH)
- [Esa-Matti Suuronen](https://x.com/esamatti)
- [Ilya Semenov](https://github.com/IlyaSemenov) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=IlyaSemenov)
- [Patricio Palladino](https://github.com/alcuadrado)
- [Kevin Peno](https://github.com/kevinpeno) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=kevinpeno)
- [Dom Parfitt](https://github.com/DomParfitt)
- [Eduardo Rafael](https://x.com/TheEduardoRFS) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=EduardoRFS)
- [Andrew C. Dvorak](https://github.com/acdvorak) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=acdvorak)
- [Adam Russell](https://github.com/a1russell) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=a1russell)
- [Piotr Szlachciak](https://github.com/sz-piotr) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=sz-piotr)
- [Mikhail Swift](https://github.com/mikhailswift) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=mikhailswift)
- [Ryan Zhang](https://github.com/DevilZh)
- [Francesco Borzì](https://www.linkedin.com/in/francesco-borzi/) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=FrancescoBorzi)
- [Marnick L'Eau](https://github.com/leaumar)
- [Egor Gorbachev](https://github.com/kubk)
- [Bill Barry](https://github.com/bbarry) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=bbarry)
- [Andrzej Wódkiewicz](https://github.com/akwodkiewicz) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=akwodkiewicz)
- [Christian Junker](https://www.linkedin.com/in/chjdev/)
- [Matthew Leffler](https://github.com/mattleff) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=mattleff)
- [studds](https://github.com/studds) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=studds)
- [Robert Vitonsky](https://github.com/vitonsky)
- [Itay Ronen](https://github.com/itayronen) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=itayronen)
- [Yaroslav Larin](https://github.com/cyberbiont)
- [liaoyinglong](https://github.com/liaoyinglong) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=liaoyinglong)
- [Yannick Stachelscheid](https://github.com/yss14) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=yss14)
- [Peter Smolinský](https://github.com/psmolinsky) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=psmolinsky)
- [Anurag Hazra](https://github.com/anuraghazra) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=anuraghazra)
- [Bishwajit Jha](https://github.com/ajitjha393) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=ajitjha393)
- [Sergey Ukustov](https://github.com/ukstv) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=ukstv)
- [Homa Wong](https://github.com/unional) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=unional)
- [polyipseity](https://github.com/polyipseity) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=polyipseity)
- [Kristóf Poduszló](https://github.com/kripod) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=kripod)
- [MT Lewis](https://github.com/mtlewis) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=mtlewis)
- [Daniel Bertocci](https://github.com/DanielBertocci) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=DanielBertocci)
- [Myles J](https://github.com/mylesj) / [💻](https://github.com/ts-essentials/ts-essentials/commits?author=mylesj)💻 - contributions, i.e. links to commits by the user on this project
Contributions of any kind welcome! [Read more](./CONTRIBUTING.md)