Skip to content

Instantly share code, notes, and snippets.

@codeBelt
Last active May 30, 2019 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeBelt/9a42dd05b57fe7ac05e68d1e405042ca to your computer and use it in GitHub Desktop.
Save codeBelt/9a42dd05b57fe7ac05e68d1e405042ca to your computer and use it in GitHub Desktop.
TypeScript Conditional Types for DispatchProp and RouteComponentProps
import { DispatchProp } from 'react-redux';
import IAction from './IAction';
import { RouteComponentProps } from 'react-router';
export type ReduxProps<P = any, R = never> = [R] extends [never]
? DispatchProp<IAction<P>>
: DispatchProp<IAction<P>> & RouteComponentProps<R>;
// Ugly alternative way
export type ReduxProps<P = any, R = never> = DispatchProp<IAction<P>> & ([R] extends [never] ? {} : RouteComponentProps<R>);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment