Skip to content

Instantly share code, notes, and snippets.

@benadamstyles
Last active September 24, 2017 16:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benadamstyles/ffb7c4339000c2f057905ffd80af9fa5 to your computer and use it in GitHub Desktop.
Save benadamstyles/ffb7c4339000c2f057905ffd80af9fa5 to your computer and use it in GitHub Desktop.
Flow Utility Type Functions
// Below are some useful Flow utility type functions, some I've written and some I've found on the web.
// All contributions welcome!
// Extracting a data type from a maybe type, e.g. getting `string` from `?string`
type _ExtractFromMaybe<T, M: ?T> = T
export type ExtractFromMaybe<M> = _ExtractFromMaybe<*, M>
// FROM https://hackernoon.com/redux-flow-type-getting-the-maximum-benefit-from-the-fewest-key-strokes-5c006c54ec87
// Extracting the type of a function's return value
type _ExtractReturn<R, F: (...args: any[]) => R> = R
export type ExtractReturn<F> = _ExtractReturn<*, F>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment