Last active
July 15, 2019 23:11
-
-
Save punmechanic/703f0df28ce6035e174d940237891666 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Action = | |
| { type: 'ReturnsPromise' } | |
| { type: 'ReturnsUndefined' } | |
type R<A> = | |
| A extends { type: 'ReturnsPromise' } ? Promise<unknown> : never | |
| A extends { type: 'ReturnsUndefined' } ? undefined : never | |
| unknown | |
type Dispatch<A> = (action: A) => R<A> | |
const dispatch = <A>(action: A) => undefined as R<A> | |
dispatch({ type: 'ReturnsPromise' as const }).then(() => foo()) | |
// failure: dispatch returns undefined (expected) | |
dispatch({ type: 'ReturnsUndefined' as const }).then(() => null) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment