Skip to content

react-redux: conditional type inference from alias fails after re-alias support in #42284 #42421

@sandersn

Description

@sandersn

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 ... }

Metadata

Metadata

Assignees

Labels

Breaking ChangeWould introduce errors in existing codeWorking as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions