Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gikey/tool-types
Complementing TypeScript built-in types
https://github.com/gikey/tool-types
Last synced: 4 days ago
JSON representation
Complementing TypeScript built-in types
- Host: GitHub
- URL: https://github.com/gikey/tool-types
- Owner: gikey
- Created: 2021-09-18T03:23:16.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-09-20T13:47:39.000Z (about 3 years ago)
- Last Synced: 2024-03-23T21:23:03.869Z (8 months ago)
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# tool-types
Complementing TypeScript built-in types.
![](https://img.shields.io/npm/v/tool-types?style=flat-square)
![](https://img.shields.io/npm/dm/tool-types?style=flat-square)## Installation
```sh
npm install tool-types
# or yarn add tool-types
```## Usage
```ts
import { TupleUnion } from 'tool-types';type T0 = [number, string];
type T1 = TupleUnion // number | string
```## Utility Types
- [`Intersect`](#intersect)
- [`Except`](#except)
- [`UnionOmit`](#unionomit)
- [`TupleUnion`](#tupleunion)
- [`RequireAtLeastOne`](#requireatleastone)
- [`RequireAtLeastOneByKeys`](#requireatleastonebykeys)
- [`Weaken`](#weaken)
- [`Promisify`](#promisify)
- [`DeepPartial`](#deeppartial)
- [`DeepRequired`](#deeprequired)
- [`DeepReadOnly`](#deepreadonly)
- [`DeepMutable`](#deepmutable)
- [`RequiredByKeys`](#requiredbykeys)
- [`PartialByKeys`](#partialbykeys)
- [`ReadOnlyByKeys`](#readonlybykeys)
- [`MutableByKeys`](#mutablebykeys)
- [`PickAllKeys`](#pickallkeys)
- [`PickRequiredKeys`](#pickrequiredkeys)
- [`PickPartialKeys`](#pickpartialkeys)
- [`PickRequired`](#pickrequired)
- [`PickPartial`](#pickpartial)
- [`Equal`](#equal)
- [`PickReadOnlyKeys`](#pickreadonlykeys)
- [`PickReadOnly`](#pickreadonly)
- [`PickMutableKeys`](#pickmutablekeys)
- [`PickMutable`](#pickmutable)## Deprecated API
### `Intersect`
```ts
type A = {
name: string;
age: number;
};
type B = {
name: string;
address: string;
gender: number;
}// Expect: { name: string; }
type ResultType = Intersect;
```
[⇧ back to top](#utility-types)
### `Except`
```ts
type A = {
name: string;
age: number;
};
type B = {
name: string;
address: string;
gender: number;
}
// Expect: { age: number; }
type ResultType = Except;
```
[⇧ back to top](#utility-types)
### `UnionOmit`
```ts
type A = {
value: string;
disabled?: boolean;
onChange: () => void;
};
type B = {
value: number;
onChange: () => void;
};
/* Expect:
{
value: string,
disabled?: boolean;
onChange: () => void;
}
*/
type ResultType = UnionOmit;
```
[⇧ back to top](#utility-types)
### `TupleUnion`
```ts
type A = ['a', 'b', 'c'];
// Expect: 'a' | 'b' | 'c'
type ResultType = TupleUnion;
```
[⇧ back to top](#utility-types)
### `RequireAtLeastOne`
```ts
type A = {
name: string;
age: number;
}
/* Expect:
| {name?: string; age: number;}
| {name: string; age?: number;}
*/
type ResultType = RequireAtLeastOne;
```
[⇧ back to top](#utility-types)
### `RequireAtLeastOneByKeys`
```ts
type A = {
name: string;
age: number;
gender: number;
}
/* Expect:
| {
name?: string;
age: number;
gender: number;
}
| {
name: string;
age: number;
gender?: number;
}
*/
type ResultType = RequireAtLeastOneByKeys;
```
[⇧ back to top](#utility-types)
### `Weaken`
```ts
type A = {
name: string;
say(word: string): string;
}
type B = 'name'
// Expect: { name: any; say(word: string): string; }
type ResultType =Weaken;
```
[⇧ back to top](#utility-types)
### `Promisify`
```ts
const foo = (): Promise => {
return new Promise(resolve => {
resolve('hello world');
});
};
// Expect: string
type ResultType = Promisify;
```
[⇧ back to top](#utility-types)
### `DeepPartial`
```ts
type A = {
value: string;
next: {
data: number;
}
}
/* Expect:
{
value?: string;
next?: {
data?: number;
}
}
*/
type ResultType = DeepPartial;
```
[⇧ back to top](#utility-types)
### `DeepRequired`
```ts
type A = {
value?: string;
next?: {
data?: number;
}
}
/* Expect:
{
value: string;
next: {
data: number;
}
}
*/
type ResultType = DeepRequired;
```
[⇧ back to top](#utility-types)
### `DeepReadOnly`
```ts
type A = {value: string; next: { data: number; }}
/* Expect:
{
readonly value: string;
readonly next: {
readonly data: number;
}
}
*/
type ResultType = DeepReadOnly;
```
[⇧ back to top](#utility-types)
### `DeepMutable`
```ts
type A = {
readonly value: string;
readonly next: {
readonly data: number;
}
}
/* Expect:
{
value: string;
next: {
data: number;
}
}
*/
type ResultType = DeepMutable;
```
[⇧ back to top](#utility-types)
### `RequiredByKeys`
```ts
type A = {
name?: string;
age?: number;
gender?: number;
}
/* Expect:
{
name: string;
age?: number;
gender?: number;
}
*/
type ResultType = RequiredByKeys;
```
[⇧ back to top](#utility-types)
### `PartialByKeys`
```ts
type A = {
name: string;
age: number;
gender: number;
}
/* Expect:
{
name?: string;
age: number;
gender: number;
}
*/
type ResultType = PartialKeys;
```
[⇧ back to top](#utility-types)
### `ReadOnlyByKeys`
```ts
type A = {
name: string;
age: number;
gender: number;
}
/* Expect:
{
readonly name: string;
age: number;
gender: number;
}
*/
type ResultType = ReadOnlyByKeys;
```
[⇧ back to top](#utility-types)
### `MutableByKeys`
```ts
type A = {
readonly name: string;
readonly age: number;
readonly gender: number;
}
/* Expect:
{
name: string;
readonly age: number;
readonly gender: number;
}
*/
type ResultType = MutableByKeys;
```
[⇧ back to top](#utility-types)
### `PickAllKeys`
```ts
type A = {
name: string;
age?: number;
gender?: number;
}
// Expect: name | age | gender
type ResultType = PickAllKeys;
```
[⇧ back to top](#utility-types)
### `PickRequiredKeys`
```ts
type A = {
name: string;
age?: number;
gender?: number;
}
// Expect: name
type ResultType = PickRequiredKeys;
```
[⇧ back to top](#utility-types)
### `PickPartialKeys`
```ts
type A = {
name: string;
age?: number;
gender?: number;
}
// Expect: age | gender
type ResultType = PickPartialKeys;
```
[⇧ back to top](#utility-types)
### `PickRequired`
```ts
type A = {
name: string;
age?: number;
gender?: number;
}
// Expect: { name: string }
type ResultType = PickRequired;
```
[⇧ back to top](#utility-types)
### `PickPartial`
```ts
type A = {
name: string;
age?: number;
gender?: number;
}
// Expect: { age?: number; gender?: number;}
type ResultType = PickPartial;
```
[⇧ back to top](#utility-types)
### `Equal`
```ts
type A = { name: string; }
type B = { name?: string; }
// Expect: false
type ResultType = Equal;
```
[⇧ back to top](#utility-types)
### `PickReadOnlyKeys`
```ts
type A = {
readonly name: string;
age: number;
}
// Expect: name
type ResultType = PickReadOnlyKeys;
```
[⇧ back to top](#utility-types)
### `PickReadOnly`
```ts
type A = {
readonly name: string;
age: number;
}
// Expect: { readonly name: string; }
type ResultType = PickReadOnly;
```
[⇧ back to top](#utility-types)
### `PickMutableKeys`
```ts
type A = {
readonly name: string;
age: number;
}
// Expect: age
type ResultType = PickMutableKeys;
```
[⇧ back to top](#utility-types)
### `PickMutable`
```ts
type A = {
readonly name: string;
age: number;
}
// Expect: { age: number; }
type ResultType = PickMutable;
```
[⇧ back to top](#utility-types)