You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// simpler react typesdeclareclassComponent<P>{props: P;}exporttypeComponentClass<P>={new(props: P): Component<P>;};exporttypeFunctionComponent<P>=(props: P)=>null;exporttypeComponentType<P>=FunctionComponent<P>|ComponentClass<P>;// simpler react-router.d.tsexportinterfaceRouteComponentProps{route: string;}declarefunctionwithRouter<PextendsRouteComponentProps,CextendsComponentType<P>>(component: C&ComponentType<P>): ComponentClass<Omit<P,keyofRouteComponentProps>>;interfacePropsextendsRouteComponentProps{username: string;}declareconstMyComponent: ComponentType<Props>;// If I define `ComponentType` as `ComponentClass<P> | FunctionComponent<P>`:// Argument of type 'ComponentType<Props>' is not assignable to parameter of type 'ComponentClass<Props> | (ComponentClass<Props> & FunctionComponent<Props>)'.// If I define `ComponentType` as `FunctionComponent<P> | ComponentClass<P>`:// Argument of type 'ComponentType<Props>' is not assignable to parameter of type 'FunctionComponent<Props> | (FunctionComponent<Props> & ComponentClass<Props>)'.withRouter(MyComponent);
C & ComponentType<P> helps inference. For a more comprehensive test suite check the react-router declarations and tests
TypeScript Version: 3.7.0-dev.20190918
Search Terms: infer generic
Code
C & ComponentType<P>helps inference. For a more comprehensive test suite check the react-router declarations and testsA fix getting rid of
C & ComponentType<P>(DefinitelyTyped/DefinitelyTyped#38326) caused issues when usingstrictFunctionTypesExpected behavior:
No type error
Actual behavior:
Throws with a different error message depending on the order of the union members in
ComponentTypePlayground Link:
playground for 3.5.3
Related Issues:
withRouterfails withComponentTypestarting in 3.6.2 DefinitelyTyped/DefinitelyTyped#38271/cc @OliverJAsh