Repository navigation
Enum.A & "a" should be Enum.A and not never - #65658
Wesley Wigham (weswigham) wants to merge 1 commit into
Conversation
|
TypeScript Bot (@typescript-bot) perf test this |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the enum–literal intersection changes.
No open issues 🎉
What changed in this PR
This PR fixes intersection reduction in the TypeScript checker so an enum member intersected with its matching literal retains the enum member type instead of becoming never.
Changes:
- Recognizes matching enum members and plain literals during intersection and primitive-union reduction.
- Adds order-preserving replacement to the checker’s ordered set.
- Adds regression coverage and baselines for numeric and string enum intersections, operand order, and rejected assignments.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/enumLiteralIntersections.ts |
Adds enum–literal intersection regression cases. |
tsc/testdata/baselines/reference/compiler/enumLiteralIntersections.types |
Records expected enum-member type reductions. |
tsc/testdata/baselines/reference/compiler/enumLiteralIntersections.symbols |
Records symbol bindings for the regression cases. |
tsc/internal/checker/utilities.go |
Adds order-preserving set replacement. |
tsc/internal/checker/checker.go |
Preserves enum members when intersected with matching literals. |
Review effort: Balanced
Krish Khinchi (krishkhinchi)
left a comment
There was a problem hiding this comment.
Good bug fix addressing an inconsistency in TypeScript's enum intersection handling. The change should ensure enum members retain their literal identity when intersected with compatible string literal types, rather than incorrectly resolving to never. Recommendation: Approve, provided regression tests cover assignability and intersection behavior across string enums and literal types.
|
Wesley Wigham (@weswigham) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
lspComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
startupComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
TypeScript Bot (@typescript-bot) test it |
|
Wesley Wigham (@weswigham) Here are the results of running the user tests with tsc comparing Something interesting changed - please have a look. Details
|
|
Hey Wesley Wigham (@weswigham), the results of running the DT tests are ready. Everything looks the same! |
|
Wesley Wigham (@weswigham) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Wesley Wigham (@weswigham) Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
I called this out years ago in a PR as a bug, but forgot about it until today when I was reviewing some baseline changes for negated types, and saw it crop up again. You could argue that enums are opaque, but given that
Enum.Awith an underlying"a", is assignable to a"a"typed position, it's not really defensible - it's just a bug we unintentionally introduced way back in #18438 with the fastpaths we added in it, and then preserved through time.