Closed
Description
Bug Report
On DT, react-redux/react-redux-tests.tsx:1433:
interface OwnProps {
own: string;
}
const Component: React.FC<OwnProps & ReduxProps> = ({ own, dispatch }) => null;
// ~~~~~~~~ 'dispatch' does not exist on PropsWithChildren<OwnProps>
const connector = connect();
type ReduxProps = ConnectedProps<typeof connector>;
🙂 Expected behavior
The object type that's the first parameter to the arrow function should have two properties own
(from OwnProps
) and dispatch
(from ConnectedProps<typeof connector>
.
ConnectedProps
is a conditional type with a false branch never
, and it looks like the false branch is incorrectly selected:
export type ConnectedProps<TConnector> =
TConnector extends InferableComponentEnhancerWithProps<infer TInjectedProps, any>
? TInjectedProps
: never;
That must be because inference to InferableComponentEnhancerWithProps<infer TInjectedProps, any>
fails.
🙁 Actual behavior
Component: React.FC<OwnProps>
not : React.FC<OwnProps & DispatchProp>
Workaround
I observed that connect: Connect
and also that
interface Connect {
(): InferableComponentEnhancer<DispatchProp>;
// ... many other properties ...
}
export type InferableComponentEnhancer<TInjectedProps> =
InferableComponentEnhancerWithProps<TInjectedProps, {}>;
Manually de-aliasing InferableComponentEnhancer
fixes the error:
interface Connect {
(): InferableComponentEnhancerWithProps<DispatchProp, {}>;
// ... many other properties ...
}