Repository navigation
[experiment] Skip incompatible discriminants when inferring from union sources - #64695
Mateusz Burzyński (Andarist) wants to merge 1 commit into
Conversation
|
TypeScript Bot (@typescript-bot) test it |
There was a problem hiding this comment.
🔵 Needs a closer look
The draft changes broad compiler inference semantics despite strong regression coverage and warrants human evaluation against extended user tests.
0 open findings
What changed in this PR
Adds discriminant-aware filtering to union-source inference, addressing #64690 while expanding compiler regression coverage.
Changes:
- Skips source constituents with incompatible fixed discriminants.
- Tests aliases, nesting, tag types, ordering, and optional-property semantics.
- Adds diagnostics, type, and symbol baselines for both optional-property modes.
| File | Description |
|---|---|
tsc/internal/checker/inference.go |
Implements discriminant-aware inference filtering. |
tsc/testdata/tests/cases/compiler/inferenceDiscriminatedUnionSource.ts |
Adds compiler regression cases. |
tsc/testdata/baselines/reference/compiler/inferenceDiscriminatedUnionSource(exactoptionalpropertytypes=true).types |
Records inferred types. |
tsc/testdata/baselines/reference/compiler/inferenceDiscriminatedUnionSource(exactoptionalpropertytypes=true).symbols |
Records symbols. |
tsc/testdata/baselines/reference/compiler/inferenceDiscriminatedUnionSource(exactoptionalpropertytypes=true).errors.txt |
Records diagnostics. |
tsc/testdata/baselines/reference/compiler/inferenceDiscriminatedUnionSource(exactoptionalpropertytypes=false).types |
Records inferred types. |
tsc/testdata/baselines/reference/compiler/inferenceDiscriminatedUnionSource(exactoptionalpropertytypes=false).symbols |
Records symbols. |
tsc/testdata/baselines/reference/compiler/inferenceDiscriminatedUnionSource(exactoptionalpropertytypes=false).errors.txt |
Records diagnostics. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready. Everything looks the same! |
|
Jake Bailey (@jakebailey) Here are the results of running the user tests with tsc comparing Everything looks good! |
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Man, when we tried this in the JS codebase, the type comparison on every possible inference target ended up blowing up any savings we got from skipping deeper inferences on less appropriate members. But the perf suite shows it as good now, so I'm a fan. Maybe the optional prop fastpath and objecty type carve-outs are saving enough low-value comparisons it's at least perf neutral again? I'd be happier if we used |
|
Jake Bailey (@jakebailey) Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
fixes #64690
I was kinda always wondering if a logic like this could be used to cut down on inference work when dealing with discriminated unions and the referenced PR pushed me to try it out.
I'd still like to do more work on this and recheck things. That's why I'm opening this as a draft, I'd be curious what extended user tests etc would show for this