Skip to content

Improve narrowing logic for instanceof, type predicate functions, and assertion functions - #49625

Merged
Anders Hejlsberg (ahejlsberg) merged 7 commits into
mainfrom
fix31156
Jul 16, 2022
Merged

Improve narrowing logic for instanceof, type predicate functions, and assertion functions#49625
Anders Hejlsberg (ahejlsberg) merged 7 commits into
mainfrom
fix31156

Conversation

@ahejlsberg

@ahejlsbergAnders Hejlsberg (ahejlsberg) commented Jun 22, 2022

Copy link
Copy Markdown
Member

This PR improves our narrowing logic for instanceof, type predicate functions, and assertion functions. In particular, we now correctly handle situations where the narrowing target type is a union type.

Some examples:

typeFalsy=false|0|0n|''|null|undefined;declarefunctionisFalsy(value: unknown): value is Falsy;functionfx1(x: string|number|undefined){if(isFalsy(x)){x;// "" | 0 | undefined, previously undefined}}functionfx2<T>(x: T|undefined){if(isFalsy(x)){x;// (T & null) | (T & false) | (T & "") | (T & 0) | (T & 0n) | undefined, previously undefined}}functionfx3<Textendsstring|number>(x: T){if(isFalsy(x)){x;// T & "" | T & 0, previously T & Falsy}}declarefunctionisA(obj: unknown): obj is {a: false}|{b: 0};functionfx4(obj: {b: number}){if(isA(obj)){obj;// { b: 0 }, previously { b: number } & ({ a: false } | { b: 0 })}}declareclassX{x: string}declareclassXSextendsX{xs: string}declareclassY{y: string}declareclassYSextendsY{ys: string}declarefunctionisXSorY(obj: unknown): obj is XS|Y;functionfx5<TextendsX>(obj: X|YS,c: typeofXS|typeofY){if(objinstanceofc){obj;// XS | YS, previously YS}if(isXSorY(obj)){obj;// XS | YS, previously YS}}

Previously all of the above examples produced wrong results.

Fixes#31156.
Fixes#35953.
Fixes#37807.
Fixes#38869.
Fixes#39105.
Fixes#40035.
Fixes#41871.
Fixes#42101.
Fixes#43825.
Fixes#44754.
Fixes#46909.
Fixes#49588.

@ahejlsberg

Copy link
Copy Markdown
MemberAuthor

@typescript-bot

TypeScript Bot (typescript-bot) commented Jun 22, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the abridged perf test suite on this PR at fc81aff. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Jun 22, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the diff-based user code test suite on this PR at fc81aff. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Jun 22, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the extended test suite on this PR at fc81aff. You can monitor the build here.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jun 22, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the parallelized Definitely Typed test suite on this PR at fc81aff. You can monitor the build here.

@typescript-bot

Copy link
Copy Markdown
Contributor

Anders Hejlsberg (@ahejlsberg)
The results of the perf run you requested are in!

Here they are:

Comparison Report - main..49625

Metricmain49625DeltaBestWorst
Angular - node (v14.15.1, x64)
Memory used335,317k (± 0.01%)335,376k (± 0.01%)+59k (+ 0.02%)335,317k335,422k
Parse Time2.09s (± 0.68%)2.08s (± 0.43%)-0.01s (- 0.62%)2.06s2.10s
Bind Time0.91s (± 0.52%)0.91s (± 0.75%)-0.00s (- 0.11%)0.89s0.92s
Check Time5.75s (± 0.40%)5.76s (± 0.55%)+0.01s (+ 0.14%)5.71s5.82s
Emit Time6.42s (± 0.72%)6.39s (± 0.95%)-0.03s (- 0.50%)6.30s6.53s
Total Time15.17s (± 0.36%)15.13s (± 0.54%)-0.04s (- 0.24%)14.99s15.32s
Compiler-Unions - node (v14.15.1, x64)
Memory used192,554k (± 0.13%)195,458k (± 0.01%)+2,904k (+ 1.51%)195,397k195,515k
Parse Time0.86s (± 0.69%)0.85s (± 0.55%)-0.01s (- 0.70%)0.84s0.86s
Bind Time0.58s (± 1.29%)0.57s (± 0.86%)-0.00s (- 0.52%)0.57s0.59s
Check Time7.73s (± 0.61%)8.38s (± 1.29%)+0.66s (+ 8.50%)8.22s8.76s
Emit Time2.52s (± 0.55%)2.52s (± 0.74%)+0.00s (+ 0.16%)2.48s2.56s
Total Time11.68s (± 0.47%)12.33s (± 0.96%)+0.65s (+ 5.56%)12.15s12.73s
Monaco - node (v14.15.1, x64)
Memory used325,607k (± 0.00%)325,478k (± 0.01%)-129k (- 0.04%)325,415k325,532k
Parse Time1.59s (± 0.78%)1.58s (± 0.66%)-0.01s (- 0.63%)1.56s1.61s
Bind Time0.80s (± 0.60%)0.79s (± 0.92%)-0.00s (- 0.63%)0.78s0.81s
Check Time5.72s (± 0.69%)5.67s (± 0.30%)-0.05s (- 0.82%)5.64s5.72s
Emit Time3.37s (± 0.73%)3.35s (± 0.74%)-0.02s (- 0.62%)3.29s3.41s
Total Time11.46s (± 0.52%)11.39s (± 0.28%)-0.08s (- 0.68%)11.33s11.46s
TFS - node (v14.15.1, x64)
Memory used288,754k (± 0.01%)288,722k (± 0.01%)-32k (- 0.01%)288,692k288,770k
Parse Time1.34s (± 1.52%)1.33s (± 1.20%)-0.02s (- 1.12%)1.30s1.36s
Bind Time0.75s (± 0.94%)0.74s (± 0.64%)-0.01s (- 0.80%)0.73s0.75s
Check Time5.33s (± 0.38%)5.30s (± 0.39%)-0.03s (- 0.47%)5.27s5.35s
Emit Time3.59s (± 2.15%)3.61s (± 1.95%)+0.01s (+ 0.39%)3.45s3.74s
Total Time11.02s (± 0.93%)10.98s (± 0.57%)-0.03s (- 0.29%)10.84s11.09s
material-ui - node (v14.15.1, x64)
Memory used446,332k (± 0.00%)446,216k (± 0.06%)-116k (- 0.03%)445,138k446,373k
Parse Time1.89s (± 0.50%)1.88s (± 0.40%)-0.01s (- 0.42%)1.87s1.91s
Bind Time0.72s (± 1.23%)0.72s (± 1.26%)-0.00s (- 0.41%)0.70s0.74s
Check Time13.17s (± 0.59%)13.14s (± 0.63%)-0.03s (- 0.22%)12.96s13.31s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.79s (± 0.49%)15.75s (± 0.50%)-0.03s (- 0.22%)15.56s15.90s
xstate - node (v14.15.1, x64)
Memory used541,028k (± 0.00%)541,672k (± 0.00%)+645k (+ 0.12%)541,617k541,714k
Parse Time2.63s (± 0.49%)2.63s (± 0.34%)+0.00s (+ 0.04%)2.62s2.65s
Bind Time1.17s (± 0.81%)1.17s (± 1.15%)+0.00s (+ 0.17%)1.14s1.19s
Check Time1.53s (± 0.52%)1.53s (± 0.49%)+0.00s (+ 0.07%)1.52s1.55s
Emit Time0.07s (± 4.92%)0.07s (± 3.14%)🟩-0.00s (- 4.05%)0.07s0.08s
Total Time5.41s (± 0.30%)5.41s (± 0.33%)-0.00s (- 0.06%)5.38s5.45s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v14.15.1, x64)
BenchmarkNameIterations
Current4962510
Baselinemain10

Developer Information:

Download Benchmark

@typescript-bot

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here.

@typescript-bot

Copy link
Copy Markdown
Contributor

Anders Hejlsberg (@ahejlsberg)
Great news! no new errors were found between main..refs/pull/49625/merge

@ahejlsberg

Copy link
Copy Markdown
MemberAuthor

@typescript-bot

TypeScript Bot (typescript-bot) commented Jun 22, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the diff-based user code test suite on this PR at 37bfa91. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Jun 22, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the abridged perf test suite on this PR at 37bfa91. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Jun 22, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the extended test suite on this PR at 37bfa91. You can monitor the build here.

@typescript-bot

Copy link
Copy Markdown
Contributor

Anders Hejlsberg (@ahejlsberg)
Great news! no new errors were found between main..refs/pull/49625/merge

@typescript-bot

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here.

@RyanCavanaugh

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) pack this

@typescript-bot

TypeScript Bot (typescript-bot) commented Jun 22, 2022

Copy link
Copy Markdown
Contributor

Heya Ryan Cavanaugh (@RyanCavanaugh), I've started to run the tarball bundle task on this PR at 37bfa91. You can monitor the build here.

@typescript-bot

Copy link
Copy Markdown
Contributor

Anders Hejlsberg (@ahejlsberg)
The results of the perf run you requested are in!

Here they are:

Comparison Report - main..49625

Metricmain49625DeltaBestWorst
Angular - node (v14.15.1, x64)
Memory used335,331k (± 0.01%)335,388k (± 0.01%)+57k (+ 0.02%)335,295k335,490k
Parse Time2.07s (± 0.65%)2.08s (± 0.46%)+0.01s (+ 0.39%)2.06s2.10s
Bind Time0.90s (± 0.49%)0.91s (± 0.49%)+0.01s (+ 0.67%)0.90s0.92s
Check Time5.75s (± 0.25%)5.75s (± 0.39%)-0.00s (- 0.03%)5.69s5.80s
Emit Time6.40s (± 0.91%)6.44s (± 0.89%)+0.03s (+ 0.52%)6.29s6.53s
Total Time15.13s (± 0.47%)15.17s (± 0.44%)+0.04s (+ 0.27%)15.02s15.28s
Compiler-Unions - node (v14.15.1, x64)
Memory used192,649k (± 0.01%)195,450k (± 0.01%)+2,801k (+ 1.45%)195,393k195,504k
Parse Time0.85s (± 0.47%)0.85s (± 0.58%)+0.00s (+ 0.59%)0.85s0.87s
Bind Time0.57s (± 0.87%)0.58s (± 1.52%)+0.01s (+ 0.87%)0.57s0.61s
Check Time7.63s (± 0.44%)8.38s (± 0.97%)+0.75s (+ 9.76%)8.23s8.58s
Emit Time2.52s (± 0.68%)2.54s (± 1.39%)+0.03s (+ 1.03%)2.48s2.64s
Total Time11.57s (± 0.29%)12.35s (± 0.60%)+0.78s (+ 6.78%)12.24s12.51s
Monaco - node (v14.15.1, x64)
Memory used325,616k (± 0.00%)325,488k (± 0.01%)-129k (- 0.04%)325,441k325,530k
Parse Time1.57s (± 0.51%)1.59s (± 0.47%)+0.02s (+ 1.21%)1.58s1.61s
Bind Time0.79s (± 0.28%)0.79s (± 0.46%)+0.00s (+ 0.63%)0.79s0.80s
Check Time5.67s (± 0.51%)5.69s (± 0.68%)+0.02s (+ 0.42%)5.63s5.78s
Emit Time3.33s (± 0.76%)3.36s (± 0.84%)+0.03s (+ 0.87%)3.32s3.45s
Total Time11.36s (± 0.31%)11.43s (± 0.46%)+0.08s (+ 0.70%)11.33s11.54s
TFS - node (v14.15.1, x64)
Memory used288,773k (± 0.01%)288,739k (± 0.01%)-34k (- 0.01%)288,655k288,826k
Parse Time1.32s (± 1.18%)1.33s (± 0.55%)+0.00s (+ 0.23%)1.31s1.34s
Bind Time0.75s (± 0.63%)0.76s (± 0.90%)+0.01s (+ 0.80%)0.74s0.77s
Check Time5.31s (± 0.34%)5.31s (± 0.50%)-0.01s (- 0.11%)5.26s5.38s
Emit Time3.57s (± 1.74%)3.63s (± 1.83%)+0.06s (+ 1.79%)3.44s3.69s
Total Time10.95s (± 0.65%)11.02s (± 0.59%)+0.07s (+ 0.62%)10.84s11.13s
material-ui - node (v14.15.1, x64)
Memory used446,341k (± 0.00%)446,338k (± 0.01%)-3k (- 0.00%)446,300k446,422k
Parse Time1.89s (± 0.47%)1.90s (± 0.56%)+0.02s (+ 0.85%)1.87s1.92s
Bind Time0.72s (± 1.22%)0.73s (± 1.05%)+0.00s (+ 0.28%)0.71s0.74s
Check Time13.05s (± 0.50%)13.22s (± 0.67%)+0.16s (+ 1.24%)13.03s13.47s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.66s (± 0.41%)15.84s (± 0.53%)+0.18s (+ 1.12%)15.66s16.09s
xstate - node (v14.15.1, x64)
Memory used541,039k (± 0.01%)541,040k (± 0.01%)+1k (+ 0.00%)540,989k541,111k
Parse Time2.63s (± 0.49%)2.65s (± 0.62%)+0.02s (+ 0.72%)2.62s2.69s
Bind Time1.17s (± 0.79%)1.18s (± 1.24%)+0.01s (+ 1.11%)1.15s1.21s
Check Time1.53s (± 0.78%)1.54s (± 0.73%)+0.01s (+ 0.59%)1.52s1.56s
Emit Time0.07s (± 4.13%)0.07s (± 4.92%)+0.00s (+ 2.78%)0.07s0.08s
Total Time5.41s (± 0.35%)5.44s (± 0.54%)+0.03s (+ 0.55%)5.37s5.50s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v14.15.1, x64)
BenchmarkNameIterations
Current4962510
Baselinemain10

Developer Information:

Download Benchmark

@typescript-bot

TypeScript Bot (typescript-bot) commented Jun 22, 2022

Copy link
Copy Markdown
Contributor

Hey Ryan Cavanaugh (@RyanCavanaugh), I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
"devDependencies": {
"typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/128629/artifacts?artifactName=tgz&fileId=9370A02BE9286083A98BB5F91ED39114FDC7E27C11CF7BF17C728DC44CF30EDE02&fileName=/typescript-4.8.0-insiders.20220622.tgz"
}
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@4.8.0-pr-49625-17".;

@ahejlsberg

Copy link
Copy Markdown
MemberAuthor

TypeScript Bot (@typescript-bot) perf test faster

@typescript-bot

TypeScript Bot (typescript-bot) commented Jul 5, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the abridged perf test suite on this PR at 960ad11. You can monitor the build here.

Update: The results are in!

@typescript-bot

Copy link
Copy Markdown
Contributor

Anders Hejlsberg (@ahejlsberg)
The results of the perf run you requested are in!

Here they are:

Comparison Report - main..49625

Metricmain49625DeltaBestWorst
Angular - node (v14.15.1, x64)
Memory used335,347k (± 0.01%)335,396k (± 0.01%)+49k (+ 0.01%)335,324k335,442k
Parse Time2.07s (± 0.68%)2.05s (± 0.38%)-0.02s (- 0.82%)2.04s2.07s
Bind Time0.90s (± 0.54%)0.90s (± 0.77%)-0.01s (- 1.00%)0.88s0.91s
Check Time5.82s (± 0.48%)5.78s (± 0.58%)-0.04s (- 0.70%)5.73s5.90s
Emit Time6.43s (± 0.53%)6.38s (± 0.54%)-0.05s (- 0.76%)6.29s6.45s
Total Time15.22s (± 0.27%)15.10s (± 0.39%)-0.12s (- 0.76%)15.01s15.29s
Compiler-Unions - node (v14.15.1, x64)
Memory used193,161k (± 0.38%)193,054k (± 0.01%)-107k (- 0.06%)192,965k193,100k
Parse Time0.85s (± 0.58%)0.85s (± 0.61%)+0.00s (+ 0.35%)0.84s0.86s
Bind Time0.57s (± 1.51%)0.57s (± 1.19%)+0.00s (+ 0.35%)0.56s0.59s
Check Time6.77s (± 0.61%)6.72s (± 0.47%)-0.05s (- 0.68%)6.64s6.80s
Emit Time2.52s (± 0.73%)2.51s (± 0.66%)-0.01s (- 0.44%)2.49s2.55s
Total Time10.71s (± 0.45%)10.66s (± 0.37%)-0.05s (- 0.51%)10.55s10.72s
Monaco - node (v14.15.1, x64)
Memory used325,670k (± 0.00%)325,538k (± 0.00%)-131k (- 0.04%)325,503k325,564k
Parse Time1.58s (± 0.48%)1.58s (± 0.52%)-0.01s (- 0.51%)1.56s1.60s
Bind Time0.80s (± 1.04%)0.79s (± 0.56%)-0.00s (- 0.38%)0.78s0.80s
Check Time5.69s (± 0.30%)5.69s (± 0.62%)-0.01s (- 0.12%)5.63s5.79s
Emit Time3.39s (± 0.81%)3.35s (± 0.76%)-0.04s (- 1.18%)3.30s3.42s
Total Time11.46s (± 0.29%)11.40s (± 0.50%)-0.06s (- 0.52%)11.31s11.57s
TFS - node (v14.15.1, x64)
Memory used288,762k (± 0.01%)288,742k (± 0.01%)-19k (- 0.01%)288,716k288,781k
Parse Time1.34s (± 0.99%)1.32s (± 1.55%)-0.02s (- 1.71%)1.29s1.36s
Bind Time0.77s (± 3.58%)0.78s (± 4.54%)+0.01s (+ 1.70%)0.73s0.86s
Check Time5.34s (± 0.48%)5.31s (± 0.26%)-0.03s (- 0.58%)5.29s5.35s
Emit Time3.56s (± 2.02%)3.54s (± 2.10%)-0.02s (- 0.51%)3.45s3.70s
Total Time11.01s (± 0.89%)10.95s (± 0.74%)-0.06s (- 0.57%)10.84s11.19s
material-ui - node (v14.15.1, x64)
Memory used446,700k (± 0.01%)446,663k (± 0.01%)-38k (- 0.01%)446,605k446,715k
Parse Time1.88s (± 0.64%)1.87s (± 0.36%)-0.01s (- 0.37%)1.86s1.88s
Bind Time0.74s (± 1.36%)0.73s (± 1.04%)-0.01s (- 1.49%)0.71s0.74s
Check Time13.16s (± 0.48%)13.07s (± 0.43%)-0.08s (- 0.61%)12.97s13.26s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.77s (± 0.45%)15.67s (± 0.34%)-0.10s (- 0.65%)15.57s15.84s
xstate - node (v14.15.1, x64)
Memory used541,189k (± 0.00%)541,158k (± 0.00%)-31k (- 0.01%)541,131k541,204k
Parse Time2.61s (± 0.43%)2.60s (± 0.39%)-0.01s (- 0.46%)2.58s2.62s
Bind Time1.15s (± 1.17%)1.15s (± 0.81%)+0.00s (+ 0.26%)1.13s1.17s
Check Time1.55s (± 0.76%)1.53s (± 0.32%)-0.02s (- 1.03%)1.52s1.54s
Emit Time0.07s (± 4.66%)0.07s (± 4.92%)+0.00s (+ 1.37%)0.07s0.08s
Total Time5.38s (± 0.45%)5.36s (± 0.31%)-0.02s (- 0.39%)5.32s5.40s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v14.15.1, x64)
BenchmarkNameIterations
Current4962510
Baselinemain10

Developer Information:

Download Benchmark

@ahejlsberg

Copy link
Copy Markdown
MemberAuthor

@typescript-bot

TypeScript Bot (typescript-bot) commented Jul 5, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the extended test suite on this PR at 960ad11. You can monitor the build here.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jul 5, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the diff-based user code test suite on this PR at 960ad11. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Jul 5, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the parallelized Definitely Typed test suite on this PR at 960ad11. You can monitor the build here.

@typescript-bot

Copy link
Copy Markdown
Contributor

Anders Hejlsberg (@ahejlsberg)
Great news! no new errors were found between main..refs/pull/49625/merge

@typescript-bot

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here.

Comment threadsrc/compiler/checker.ts
Comment threadsrc/compiler/checker.ts
@jakebailey

Copy link
Copy Markdown
Member

Is this for the 4.8 RC, or is this waiting for 4.9?

(Wondering because I was hoping to make this main's LKG as it might fix a few workarounds I have on my "enable strictFunctionTypes" branch.)

Nathan Shively-Sanders (sandersn) added a commit to DefinitelyTyped/DefinitelyTyped that referenced this pull request Jul 21, 2022
microsoft/TypeScript#49625 improves handling of
unions in type predicates so that unions are correctly preserved. This
breaks types.isMap in node.
For now I just changed the tests' expected type, but the type of isMap doesn't
make much sense to me. It should probably be changed, but that's a much
more complex task.
This break is tracked at
microsoft/TypeScript#49988 although it's
correct, I think, so not very likely to be reverted.
Nathan Shively-Sanders (sandersn) added a commit to DefinitelyTyped/DefinitelyTyped that referenced this pull request Jul 22, 2022
* Update node types.isMap tests
microsoft/TypeScript#49625 improves handling of
unions in type predicates so that unions are correctly preserved. This
breaks types.isMap in node.
For now I just changed the tests' expected type, but the type of isMap doesn't
make much sense to me. It should probably be changed, but that's a much
more complex task.
This break is tracked at
microsoft/TypeScript#49988 although it's
correct, I think, so not very likely to be reverted.
* Change test for isSet too
Nathan Shively-Sanders (sandersn) added a commit to DefinitelyTyped/DefinitelyTyped that referenced this pull request Jul 22, 2022
TS 4.8 improves narrowing of type predicates when a union is passed in.
This changes the return type of a couple of underscore and weak-napi
functions. For now I just updated the tests, since underscore's change
is pretty minor. And weak-napi's types
probably need to be rewritten substantially, which would probably result
in fixing this change.
See microsoft/TypeScript#49625 for the change.
Nathan Shively-Sanders (sandersn) added a commit to DefinitelyTyped/DefinitelyTyped that referenced this pull request Jul 22, 2022
TS 4.8 improves narrowing of type predicates when a union is passed in.
This changes the return type of a couple of underscore and weak-napi
functions. For now I just updated the tests, since underscore's change
is pretty minor. And weak-napi's types
probably need to be rewritten substantially, which would probably result
in fixing this change.
See microsoft/TypeScript#49625 for the change.
@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.