Skip to content

Instantly share code, notes, and snippets.

@anthony2025
Created August 21, 2018 15:40
Show Gist options
  • Save anthony2025/bef26d86f9ccd269e846faf77b6f3ad6 to your computer and use it in GitHub Desktop.
Save anthony2025/bef26d86f9ccd269e846faf77b6f3ad6 to your computer and use it in GitHub Desktop.
Alternative to now deprecated existential type (*)
// To get the return type of a function you can use this helper
export type ExtractReturn<Fn> = $Call<<T>((...Iterable<any>) => T) => T, Fn>;
// Example of usage:
const mapDispatchToProps = (dispatch: Dispatch) => ({
actions: {
setCompany: ({ companyId, domainName }) =>
dispatch(
setCompany({
companyId,
domainName,
}),
),
},
});
type ReduxActions = ExtractReturn<typeof mapDispatchToProps>;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment