Skip to content

Instantly share code, notes, and snippets.

@ivangabriele
Last active November 8, 2018 19:54
Show Gist options
  • Save ivangabriele/f689f76c95b9ded166a30a68851b47c8 to your computer and use it in GitHub Desktop.
Save ivangabriele/f689f76c95b9ded166a30a68851b47c8 to your computer and use it in GitHub Desktop.
Typescript useful functions & helpers list.

Typescript Useful Functions & Helpers

Objects

type Diff<T extends string, U extends string> = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T]
type Omit<T, K extends Extract<keyof T, string>> = Pick<T, Diff<Extract<keyof T, string>, K>>
type OrNull<T> = T | null
type PartialOrNull<T> = OrNull<Partial<T>>
type ReadOnly<T> = {
    readonly [P in keyof T]: T[P];
}

Classes

Constructor

type Constructor<T> = new(...args: any[]) => T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment