Skip to content

Instantly share code, notes, and snippets.

@miloszpp
Last active July 26, 2019 17:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save miloszpp/8cdf68c12db923ad28aa9ed8b688690f to your computer and use it in GitHub Desktop.
Save miloszpp/8cdf68c12db923ad28aa9ed8b688690f to your computer and use it in GitHub Desktop.
declare function bind<T>(component: React.ComponentType<T & InjectedProps>): React.ComponentType<T>;
declare class A<B> extends React.Component<PubProps<B> & InjectedProps> { }
const APrimeComponent = bind(A);
// type inferred to: React.ComponentType<PubProps<unknown>>
declare function AFunc<B>(props: PubProps<B> & InjectedProps): React.ReactElement;
const AFuncPrimeComponent = bind(AFunc);
// type inferred to: React.ComponentType<PubProps<unknown>>
declare function bindHack<T>(component: (props: T & InjectedProps) => React.ReactElement): (props: T) => React.ReactElement;
const AFuncPrimeComponentHack = bindHack(AFunc);
// type inferred correctly! AFuncPrimeComponentHack is generic
const render = () => <AFuncPrimeComponentHack foo={5} />;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment