FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add cache to `getSimplifiedConditionalType` by ahejlsberg · Pull Request #64648 · microsoft/TypeScript · GitHub

Repository navigation

Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .go  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 11 additions & 0 deletions tsc/internal/checker/checker.go
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
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ const (
CachedTypeKindDecoratorContextStatic
CachedTypeKindDecoratorContextPrivate
CachedTypeKindDecoratorContextPrivateStatic
CachedTypeKindSimplifiedConditionalType
)

// CachedTypeKey
Expand Down Expand Up @@ -28507,6 +28508,16 @@ func (c *Checker) distributeIndexOverObjectType(objectType *Type, indexType *Typ
}

func (c *Checker) getSimplifiedConditionalType(t *Type, writing bool) *Type {
key := CachedTypeKey{kind: CachedTypeKindSimplifiedConditionalType, typeId: t.id}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
}

if cached, ok := c.cachedTypes[key]; ok {
return cached
}
result := c.getSimplifiedConditionalTypeWorker(t, writing)
c.cachedTypes[key] = result
return result
}

func (c *Checker) getSimplifiedConditionalTypeWorker(t *Type, writing bool) *Type {
checkType := t.AsConditionalType().checkType
extendsType := t.AsConditionalType().extendsType
trueType := c.getTrueTypeFromConditionalType(t)
Expand Down
Loading

Back | FazBrowse Home | New Git URL