type-plus
Provides additional types and type adjusted utilities for typescript
API
Identity type
Id<T>
: generic Id typecreateId<T>(type: T, value: string): Id<T>
: create idcreateIdCreator<T>(type: T): (value: string) => Id<T>
: create an id creator
Constant Types
JSONTypes
: all JSON compatible types.KeyTypes
: type of all keys.PrimitiveTypes
: all primitive types, including Function
, symbol
, and bigint
Object Key functions
filterKey()
: type adjusted filter by key.findKey()
: type adjusted find by key.forEachKey()
: type adjusted for each by key.mapKey()
: type adjusted map by key.reduceKey()
: type adjusted reduce by key.
Array function
literalArray(...entries)
: return an array those items are restricted to the provided literals.
Promise function
isPromise<R>(subject: any)
: isPromise()
type guard.PromiseValue<P>
: Gets the type within the Promise.mapSeries()
: Similar to bluebird.mapSeries()
but works with async
/await
Nominal Type
Flavor<FlavorT, T>
: a flavored nominal type.Brand<BrandT, T>
: a branded nominal type.createBrandCreator<BrandT, T>()
: creates a brand creator to create branded nominal type.
Type manipulation
Except<T, K>
: From T
, pick a set of properties whose keys are not in the union K
. This is the opposite of Pick<T, K>
ExcludePropType<T, U>
: excludes type U
from properties in T
.PartialPick<T, U>
: makes the properties specified in U
becomes optional.PartialExcept<T, U>
: makes the properties not specified in U
becomes optional.RecursivePartial<T>
: make type T
optional recursively.RecursiveRequired<T>
: make type T
required recursively.required(...)
: merge options and removing Partial<T>
. From unpartial
requiredDeep(...)
: merge options deeply and removing Partial<T>
. From unpartial
RequiredPick<T, U>
: makes the properties specified in U
becomes required.RequiredExcept<T, U>
: makes the properties not specified in U
becomes required.RecursiveIntersect<T, U>
: intersect type U
onto T
recursively.ValueOf<T>
: type of the value of the properties of T
.tryAssign<S, T>(from: S, to: T)
: try assign from
to to
. Return type never
if not possible.- PropType: ...no helper type for this. Just do
YourType['propName']
Type assertion
There are several type assertion functions inside typeAssert
.
isXXX(value)
: ensure typeof value
is XXX
noXXX(value)
: ensure typeof value
does not contain XXX
. i.e. cannot assign XXX
to value
.
Attribution
Some of the code in this library are created by other people in the TypeScript community.
I merely adding them in and may be making some adjustments.
When ever possible, I add attribution to the person who created those code in the file.
Contribute
npm install
git checkout -b <branch>
npm run watch
git commit -m "<commit message>"
git push