Repository navigation
Add cache to getSimplifiedConditionalType - #64648
Conversation
|
TypeScript Bot (@typescript-bot) test it |
|
Hey Anders Hejlsberg (@ahejlsberg), the results of running the DT tests are ready. Everything looks the same! |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The cache must distinguish read and write simplification modes to avoid reusing incorrect results.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Adds caching for simplified conditional types to improve checker performance.
Changes:
- Adds a conditional-type cache kind.
- Splits cached orchestration from simplification logic.
| File | Description |
|---|---|
tsc/internal/checker/checker.go |
Caches conditional-type simplification results. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| } | ||
|
|
||
| func (c *Checker) getSimplifiedConditionalType(t *Type, writing bool) *Type { | ||
| key := CachedTypeKey{kind: CachedTypeKindSimplifiedConditionalType, typeId: t.id} |
There was a problem hiding this comment.
regression tests for the above:
type Value<T extends { a: string; b: number }> = T["a" | "b"] extends unknown
? T["a" | "b"]
: never;
function test<T extends { a: string; b: number }>(value: Value<T>, a: T["a"]) {
const read: T["a"] | T["b"] = value;
const write: Value<T> = a; // errors
}There was a problem hiding this comment.
Implemented separate read/write cache kinds and added regression coverage. Commit: dbb752eff.
|
Anders Hejlsberg (@ahejlsberg) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the user tests with tsc comparing Everything looks good! |
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
|
No measurable effect on perf tests, likely because we don't have react tests which is where it's supposed to help. |
Co-authored-by: ahejlsberg <4226954+ahejlsberg@users.noreply.github.com>
Jake Bailey (jakebailey)
left a comment
There was a problem hiding this comment.
Still want this?

With this PR we consistently cache results in
getSimplifiedType. Previously, we cached results for indexed access types but not conditional types. Found in performance experiments by Bun team.