-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react-redux: conditional type inference from alias fails after re-alias support in #42284 #42421
Comments
The core issue here is that with our improved type alias preservation we now give distinct identities to otherwise equivalent instantiations of It's possible we could improve inference between instantiated signatures that originate in the same signature declaration and fix the issue that way, but I'm not too hopeful. |
Looking a little deeper, the issue is that export type ConnectedProps<TConnector> =
TConnector extends InferableComponentEnhancerWithProps<infer TInjectedProps, any> ?
unknown extends TInjectedProps ?
TConnector extends InferableComponentEnhancer<infer TInjectedProps> ?
TInjectedProps :
never :
TInjectedProps :
never; This fixes the issue and works in a backwards compatible matter. |
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.
I put up a workaround PR for react-redux types. |
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.
@DanielRosenwasser We should include this in the release notes as a scenario that might be broken by #42284. |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
I understand what is happening, but I don't know if I can reliably communicate that in the release notes for the average user though. I'll think on it. |
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.
Bug Report
On DT, react-redux/react-redux-tests.tsx:1433:
🙂 Expected behavior
The object type that's the first parameter to the arrow function should have two properties
own
(fromOwnProps
) anddispatch
(fromConnectedProps<typeof connector>
.ConnectedProps
is a conditional type with a false branchnever
, and it looks like the false branch is incorrectly selected: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 thatManually de-aliasing
InferableComponentEnhancer
fixes the error:The text was updated successfully, but these errors were encountered: