-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Missing reduction step in a union of intersections with bounded type parameter #48718
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
Comments
It's not clear how we'd come to that conclusion in a tractable amount of time. From the outside you can see why that's happening, but that broader perspective isn't present during the evaluation of If you think you can fix this feel free to send a PR, but I don't think this is something we're likely to be able to address given that the proposed reduction rule would have to be able to figure out that it's inside a context where the type parameter is effectively bounded and that the expansion is in a place where it's safe to "undo" it -- the posited reduction rule is, I think, capable of causing incompleteness in other currently-working programs. |
@RyanCavanaugh @jcalz thinking about it, I wonder if we have some sort of regression here because the following seems to be unsound but accepted by TS function visitNode2<K extends DropbearNode['type']>(
node1: Readonly<Extract<DropbearNode, { type: K }>>,
node2: Readonly<Extract<DropbearNode, { type: K }>>,
v: Visitor) {
v[node1.type as K](node2)
} The cast of the declare const v: Visitor
declare const node1: NumericLiteral
declare const node2: CallExpression
visitNode<"NumericLiteral" | "CallExpression">(node1, node2, v) In the worst case |
This was an intentional trade-off to enable the pattern where you have a single value to infer the type parameter from; see https://devblogs.microsoft.com/typescript/announcing-typescript-4-6/#indexed-access-inference-improvements. |
This design limitation has been lifted by #56515 π |
Bug Report
π Search Terms
reduction, generic, union, intersection
π Version & Regression Information
This bug is also the 'Nightly' version. Versions prior to
4.6.2
give even more errors.β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
typeof node.type
is inferred as(K & "NumericLiteral") | (K & "StringLiteral") | (K & "Identifier") | (K & "CallExpression")
that it is equal toK
itself considering thatK extends "NumericLiteral" | "StringLiteral" | "Identifier" | "CallExpression"
.Something goes really wrong when I try to use
node.type
as an index, maybe because its type doesn't perform well if used as an index to access theVisitor
type.π Expected behavior
typeof node.type
inferred asK
because it is simpler to interact with and doesn't give problems if used as an index.The text was updated successfully, but these errors were encountered: