https://github.com/gilbarbara/types
Reusable typescript typings
https://github.com/gilbarbara/types
Last synced: 9 months ago
JSON representation
Reusable typescript typings
- Host: GitHub
- URL: https://github.com/gilbarbara/types
- Owner: gilbarbara
- License: mit
- Created: 2022-04-22T17:21:34.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-02T23:25:31.000Z (over 2 years ago)
- Last Synced: 2025-04-10T14:34:28.703Z (9 months ago)
- Language: TypeScript
- Size: 876 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @gilbarbara/types
[](https://badge.fury.io/js/%40gilbarbara%2Ftypes) [](https://github.com/gilbarbara/types/actions/workflows/main.yml)
Reusable typescript typings.
## Setup
```sh
npm i @gilbarbara/types
```
For convenience, the `type-fest` package is re-exported.
## Types
### Aliases
```typescript
type NumberOrNull = number | null;
type StringOrNull = string | null;
type StringOrNumber = string | number;
type PlainObject = Record;
type GenericFunction = (...arguments_: any[]) => T;
type VoidFunction = () => void;
```
### Common
```typescript
type AsyncStatus = 'IDLE' | 'PENDING' | 'SUCCESS' | 'ERROR';
interface AsyncFlow {
message: string;
status: AsyncStatus;
}
interface AsyncFlowWithCache extends AsyncFlow {
updatedAt: number;
}
interface AsyncFlowWithData extends AsyncFlow {
data: T;
}
interface AsyncFlowWithDataAndCache extends AsyncFlowWithData {
updatedAt: number;
}
type HttpMethods =
| 'CONNECT'
| 'DELETE'
| 'GET'
| 'HEAD'
| 'OPTIONS'
| 'PATCH'
| 'POST'
| 'PUT';
interface IdName {
id: string;
name: string;
}
interface LabelValue {
label: string;
value: string;
}
```
### Utilities
```typescript
/**
* Narrow down a Record to a plain object.
*/
type NarrowPlainObject> = Exclude<
T,
Array | Function | Map | Set
>;
```
```typescript
/**
* An object without excluded types.
*/
type RemoveType = {
[Key in keyof TObject as TObject[Key] extends TExclude ? never : Key]: TObject[Key];
};
```
```typescript
/**
* A strict plain object with a specific set of keys.
*/
type StrictObject, TExpected> = TExpected & {
[Key in keyof TObject]: Key extends keyof TExpected ? TExpected[Key] : never;
};
```