Skip to content

Commit 1fd2f4a

Browse files
sandersnkaznovac
authored andcommitted
Fix react-redux on TS 4.2 (DefinitelyTyped#50762)
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.
1 parent 47d38be commit 1fd2f4a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

types/react-redux/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,11 @@ export interface Connect<DefaultState = DefaultRootState> {
303303
*/
304304
export type ConnectedProps<TConnector> =
305305
TConnector extends InferableComponentEnhancerWithProps<infer TInjectedProps, any>
306-
? TInjectedProps
306+
? unknown extends TInjectedProps
307+
? TConnector extends InferableComponentEnhancer<infer TInjectedProps>
308+
? TInjectedProps
309+
: never
310+
: TInjectedProps
307311
: never;
308312

309313
/**

0 commit comments

Comments
 (0)