Skip to content

Instantly share code, notes, and snippets.

@oriSomething
Created July 17, 2017 16:23
Show Gist options
  • Save oriSomething/595ee58d3ebb10fe2542e1f80e54b38c to your computer and use it in GitHub Desktop.
Save oriSomething/595ee58d3ebb10fe2542e1f80e54b38c to your computer and use it in GitHub Desktop.
TypeScript tricks
// Source #1: http://ideasintosoftware.com/typescript-advanced-tricks/
// Source #2: https://github.com/Microsoft/TypeScript/issues/12215#issuecomment-308052919
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 keyof T> = {[P in Diff<keyof T, K>]: T[P]};
// Example: type TCleanedUser = Omit<IUser, 'privateField1' | 'privateField2'>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment