Just types
A collection of handy Typescript types.

Contents
Installation
Install using npm
npm install -D just-types
Or using yarn
yarn add --dev just-types
List of Types
Decrement
Decrement<0>
Decrement<1>
Decrement<100>
Decrement<101>
Decrement<-10>
Note: Only handles possitive integers between 0 and 100. Returns number
for other integers.
FieldPath
FieldPath<{}>
FieldPath<{a: number; b: null}>
FieldPath<{a: number; b: {c: 1; d: 2}; e: {f: {g: {}}}}
Filter
Filter<[1, 2, true, 3, 'foo'], number>
Filter<[1, 2, true, 3, 'foo'], string>
Filter<[1, 2, true, 3, 'foo'], boolean | string>
Filter<
[{active: true; data: 1}, {active: false; data: 2}, {active: true; data: 3}, {active: false; data: 4}],
{active: true}
>
Flatten
Flatten<[]>
Flatten<[[1]]>
Flatten<[[1], [2]]>
Flatten<[[1], [[2, 3]], [[4]]]>
Flatten<[[1], [[2, 3]], [[4]]], 2>
GetField
GetField<{a: number; b: null}, 'a'>
GetField<{a: number; b: null}, 'b'>
GetField<{a: number; b: {c: 1; d: 2}; e: {f: {g: number}}}, 'e.f.g'>
GetField<{a: number; b: {c: 1; d: 2}; e: {f: {g: number}}}, 'b'>
GetField<{a: number; b: {c: 1; d: 2}; e: {f: {g: number}}}, 'e.f'>
Increment
Increment<0>
Increment<1>
Increment<100>
Increment<101>
Increment<-1>
Note: Only handles possitive integers between 0 and 100. Returns number
for other integers.
InsertAt
InsertAt<'x', 0, ['a', 'b']>
InsertAt<'x', 1, ['a', 'b']>
InsertAt<'x', 2, ['a', 'b']>
InsertAt<'x', 5, ['a', 'b']>
Join
Join<[], '-'>
Join<['a'], '-'>
Join<['a', 'b'], '-'>
MutableTuple
MutableTuple<readonly []>
MutableTuple<readonly ['a']>
MutableTuple<readonly ['a', 'b']>
Permutation
Permutation<[]>
Permutation<['a']>
Permutation<['a', 'b']>
Permutation<['a', 'b', 'c']>
Range
Range<3, 3>
Range<4, 7>
Range<0, 5>
SubArray
SubArray<['a']>
SubArray<['a', 'b']>
SubArray<['a', 'b', 'c']>
Tail
Tail<[]>
Tail<['a']>
Tail<['a', 'b']>
Tail<['a', 'b', 'c', 'd']>
Contributing
You can contribute to this library in many ways, including:
-
Reporting bugs: Simply open an issue and describe the bug. Please include a code snippet to reproduce the bug, it really helps to solve the problem quickly.
-
Suggesting new types: If you have a common use case that you think worth having its own custom type, open an issue and we will discuss it. Do you already have an implementation for it? great, make a pull request and I will review it. Please make sure your code is consistent with the rest of the codebase and use Prettier and EditorConfig to format your files.
Those are just examples, any issue or pull request is welcome :)
Changelog
1.2.0 (January 2nd 2022)
1.1.0 (December 01, 2021)
1.0.0 (November 22, 2021)
The first release containing the 7 types: