Skip to content

Instantly share code, notes, and snippets.

@source-c
Created October 24, 2024 10:41
Show Gist options
  • Save source-c/bbaec5862c63c47fbe3e87a81458ba5e to your computer and use it in GitHub Desktop.
Save source-c/bbaec5862c63c47fbe3e87a81458ba5e to your computer and use it in GitHub Desktop.
Typescript Utility Types
type OptionalTypeOrNull<T> = T | undefined | null;
type Nullish = undefined | null;
type Falsy = false | "" | 0 | 0n | Nullish;
type Truthy<T> = T extends Falsy ? never : T;
type AnyCollection = ArrayLike<unknown>;
type AnyObject = { [p: string]: AnyObject | AnyCollection | unknown };
type Maybe<T> = T | Nullish;
type MaybePromise<T> = Promise<T> | T;
type Immutable<T> = {
readonly [K in keyof T]: Immutable<T[K]>;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment