Created
July 17, 2017 16:23
-
-
Save oriSomething/595ee58d3ebb10fe2542e1f80e54b38c to your computer and use it in GitHub Desktop.
TypeScript tricks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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