Created
June 5, 2019 20:52
-
-
Save saboya/f1fea38942e0b78a141a5935a0a613c9 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
type Delegate<T> = (param: T) => any | |
type DelegateA = Delegate<{ A: string }> | |
type DelegateB = Delegate<{ B: number }> | |
type DelegateC = Delegate<{ C: object }> | |
type ExtractArgument<T> = T extends (option: infer U) => void ? U : never | |
type IntersectionOptions = ExtractArgument<DelegateA> | |
& ExtractArgument<DelegateB> | |
& ExtractArgument<DelegateC> | |
type UnionOptions = ExtractArgument<DelegateA> | |
| ExtractArgument<DelegateB> | |
| ExtractArgument<DelegateC> | |
type IntersectionFactoryType = (options: IntersectionOptions) => void | |
type UnionFactoryType = (options: UnionOptions) => void | |
const intersectionFactory: IntersectionFactoryType = (options) => { | |
console.log('i') | |
} | |
const unionFactory: UnionFactoryType = (options) => { | |
console.log('u') | |
} | |
unionFactory({ A: 'bla' }) | |
intersectionFactory({ A: 'bla' }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment