You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unconstrained generics are incorrectly assignable to _any_ "Partial" type #30634
declareletx: Partial<HTMLElement>;functionf<T>(y: T){x=y;}f({innerHtml: Symbol()});// this is blatantly incompatible with `HTMLElement`if(x.innerHTML){x.innerHTML.toLowerCase();// We just set it to a `symbol` and not a `string`, this will error at runtime}
This is unsound when source is the empty type resulting from the constraint of an unconstrained generic type (which, if changed to unknown, catches this issue!). It's unsound when it comes from a constraint at all, actually. Fixing this will break react-redux, whose recursive Shared type (which we have in our test suite) actually only checks because of this unsoundness.
As I said in the OP, the change that introduced the bug was #26517 from what I can tell, so we've had it long enough that we have people unintentionally relying on it. react-redux's very terrible no good Shared type:
only actually typechecks in most cases because Shared is partial and most uses involve unconstrained type parameters. "no constraint" is defaulted to the empty object, which is then assignable to any partial type... like Shared. This is the only thing allowing most uses of this highly suspect pattern to pass the typechecker. Specifically this one is core - GetProps<C> is unconstrained - we know absolutely nothing about it (it's an infer type parameter or never), so how could is possibly satisfy the Shared<InjectedProps, DecorationTargetProps> constraint? It shouldn't be able to, yet this bug is why it does~
Activity
RyanCavanaugh commentedon Mar 28, 2019
Not a regression
weswigham commentedon Mar 28, 2019
As I said in the OP, the change that introduced the bug was #26517 from what I can tell, so we've had it long enough that we have people unintentionally relying on it.
react-redux's very terrible no good Shared type:only actually typechecks in most cases because
Sharedis partial and most uses involve unconstrained type parameters. "no constraint" is defaulted to the empty object, which is then assignable to any partial type... likeShared. This is the only thing allowing most uses of this highly suspect pattern to pass the typechecker. Specifically this one is core -GetProps<C>is unconstrained - we know absolutely nothing about it (it's aninfertype parameter ornever), so how could is possibly satisfy theShared<InjectedProps, DecorationTargetProps>constraint? It shouldn't be able to, yet this bug is why it does~react-redux currently relies on a TS bug (microsoft/TypeScript#30634)…
react-redux currently relies on a TS bug (microsoft/TypeScript#30634)…
Remove useless constraint
Remove useless constraint (#1306)
react-redux currently relies on a TS bug (microsoft/TypeScript#30634)…
Remove useless constraint (#1306)
jakebailey commentedon Jul 18, 2023
This one was fixed in #49119, explicitly via the first bullet in the PR description:
But, could probably use an explicit test.