Skip to content

Instantly share code, notes, and snippets.

@saboya
Created June 5, 2019 20:52
Show Gist options
  • Save saboya/f1fea38942e0b78a141a5935a0a613c9 to your computer and use it in GitHub Desktop.
Save saboya/f1fea38942e0b78a141a5935a0a613c9 to your computer and use it in GitHub Desktop.
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