Skip to content

Commit

Permalink
Fix react-redux on TS 4.2
Browse files Browse the repository at this point in the history
Typescript 4.2 breaks react-redux' types in a subtle way, described at
microsoft/TypeScript#42421. That changes preserves type aliases, but it
also treats them more nominally for the purposes of inference.

The result is that ConnectedProps, which normally tries to infer a type
argument from InferableComponentEnhancerWithProps, needs to add a
fallback inference from InferableComponentEnhancer, *even though* the
latter is just a type alias.

This is a non-breaking change; it would be simpler just to remove
InferableComponentEnhancer and give InferableComponentEnhancerWithProps
a type parameter default, but that would be a breaking change since both
types are exported.
  • Loading branch information
sandersn committed Jan 21, 2021
1 parent 6231aa3 commit a4212a4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion types/react-redux/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@ export interface Connect<DefaultState = DefaultRootState> {
*/
export type ConnectedProps<TConnector> =
TConnector extends InferableComponentEnhancerWithProps<infer TInjectedProps, any>
? TInjectedProps
? unknown extends TInjectedProps
? TConnector extends InferableComponentEnhancer<infer TInjectedProps>
? TInjectedProps
: never
: TInjectedProps
: never;

/**
Expand Down

0 comments on commit a4212a4

Please sign in to comment.