Created
July 18, 2019 23:38
-
-
Save alexsasharegan/810e6e551853a1e43c5d3afcf26409db to your computer and use it in GitHub Desktop.
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
/** | |
* Creates a mapped type from the `Subject` | |
* that excludes all members with types | |
* that extend the `ExcludeType`. | |
*/ | |
type ExcludeBy<Subject, ExcludeType> = { | |
[P in { | |
[K in keyof Subject]: Subject[K] extends ExcludeType ? never : K | |
}[keyof Subject]]: Subject[P] | |
}; | |
/** | |
* Creates a mapped type from the `Subject` | |
* that includes only members with types | |
* that extend the `IncludeType`. | |
*/ | |
type IncludeOnly<Subject, IncludeType> = { | |
[P in { | |
[K in keyof Subject]: Subject[K] extends IncludeType ? K : never | |
}[keyof Subject]]: Subject[P] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment