Skip to content

Instantly share code, notes, and snippets.

@StJohn3D
Created June 17, 2019 13:33
Show Gist options
  • Save StJohn3D/1de124283dfd0dac39cc22a1cee2a841 to your computer and use it in GitHub Desktop.
Save StJohn3D/1de124283dfd0dac39cc22a1cee2a841 to your computer and use it in GitHub Desktop.
Get subtype from an existing type/interface by omitting one or more properties.
/**
* Get subtype from an existing type/interface by omitting one or more properties.
*
* **Usage:**
* ```ts
* type TSubType = Omit<IOriginalType, 'Prop1' | 'Prop2'> // IOriginalType without Prop1 and Prop2
* ```
*/
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>
@StJohn3D
Copy link
Author

Real credit for this belongs to a stack overflow answer I found somewhere a while ago but I don't remember where the link is. Anyway, I was tired of looking for this used in my projects so I decided to give it a proper place in git where I can easily find it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment