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
Skip the narrowable-reference walk of unions known to contain no type variables - #64958
This PR aims to reduce compiler reference-narrowing work by skipping union traversal when a union cannot contain type variables, inspired by the linked tsrs optimization.
Changes:
Routes the union-constraint check through a new helper.
Adds a containment shortcut and documents why non-generic aliases remain eligible.
File
Description
tsc/internal/checker/checker.go
Adds the union-containment shortcut to reference narrowing.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
An unresolved narrowing regression and unvalidated hot-path performance tradeoff require further validation and human review.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Preserve narrowing for NoInfer unions with substituted constraints
tsc/internal/checker/checker.go:32305
For type U = NoInfer<{ kind: "a"; a: number } | { kind: "b"; b: number }> | { kind: "c" }, this guard skips required constraint substitution: couldContainTypeVariables(U) is false for the non-generic top-level alias, but the NoInfer constituent has a union base constraint. Consequently, for a parameter u: U, if (u.kind === "a") u.a retains the wrapped union instead of narrowing to the a branch. Preserve the walk when such substitutions may be present, or cache the exact predicate, and add a compiler regression for this case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
inspired by tsrs's: oxc-project/tsrs#715