Skip to content

Conversation

@ahejlsberg
Copy link
Member

@ahejlsbergahejlsberg commented Mar 10, 2021

In #15576 we improved control flow analysis for references of generic types with nullable constraints when those references occur in constraint positions (locations where it is known we'll fetch the constraint).

This PR expands the concept further. Specifically, when the type of a reference is or contains a generic type with a union type constraint, and when the reference is in a constraint position or has a contextual type containing no generic types (meaning constraints will determine assignability), we substitute constraints for all generic types in the type of the reference to give control flow analysis an opportunity to narrow it further. For example:

functionf1<Textendsstring|undefined>(x: T): string{if(x){x.length;// x narrowed to stringreturnx;// x narrowed to string (error before this PR)}}

Above, in x.length we substitute string | undefined for T in the type of x because x occurs in a constraint position. Similarly in return x we substitute string | undefined for T in the type of x because x has the contextual type string (due to the return type annotation on the containing function) which contains no generic types. Following substitution, control flow analysis is then able to narrow string | undefined to string based on the truthiness check in the containing if statement.

Some additional examples:

declarefunctiontakeA(a: 'a'): void;declarefunctiontakeB(b: 'b');void;functionf2<Textends'a'|'b'>(x: T){if(x==='a'){takeA(x);// x narrowed to 'a' (error before this PR)}else{takeB(x);// x narrowed to 'b' (error before this PR)}}typeA={kind: 'a',value: string};typeB={kind: 'b',value: number};functionf3<TextendsA|B>(x: T){if(x.kind==='a'){x.value;// Narrowed to string (wasn't narrowed before this PR)}else{x.value;// Narrowed to number (wasn't narrowed before this PR)}}

Fixes#13995.
Fixes#20375.
Fixes#42939.

@ahejlsberg
Copy link
MemberAuthor

@typescript-bot test this
@typescript-bot user test this
@typescript-bot run dt
@typescript-bot perf test this faster

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 10, 2021

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 10, 2021

Heya @ahejlsberg, I've started to run the perf test suite on this PR at a0fbf5c. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 10, 2021

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 10, 2021

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 10, 2021

Heya @ahejlsberg, I've started to run the parallelized community code test suite on this PR at a0fbf5c. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

@ahejlsberg
The results of the perf run you requested are in!

Here they are:

Comparison Report - master..43183

Metricmaster43183DeltaBestWorst
Angular - node (v10.16.3, x64)
Memory used348,602k (± 0.03%)348,691k (± 0.03%)+89k (+ 0.03%)348,517k348,893k
Parse Time1.92s (± 0.52%)1.92s (± 0.58%)-0.00s (- 0.16%)1.90s1.94s
Bind Time0.83s (± 0.71%)0.83s (± 0.36%)-0.01s (- 0.72%)0.82s0.83s
Check Time5.03s (± 0.56%)5.05s (± 0.36%)+0.02s (+ 0.44%)5.01s5.09s
Emit Time5.92s (± 0.38%)5.92s (± 0.77%)-0.00s (- 0.07%)5.83s6.02s
Total Time13.70s (± 0.34%)13.71s (± 0.39%)+0.01s (+ 0.07%)13.65s13.85s
Compiler-Unions - node (v10.16.3, x64)
Memory used204,777k (± 0.04%)203,960k (± 0.04%)-817k (- 0.40%)203,739k204,132k
Parse Time0.78s (± 0.86%)0.77s (± 0.44%)-0.00s (- 0.51%)0.77s0.78s
Bind Time0.53s (± 0.90%)0.52s (± 1.18%)-0.01s (- 1.14%)0.51s0.53s
Check Time7.45s (± 0.66%)7.39s (± 0.64%)-0.06s (- 0.78%)7.29s7.49s
Emit Time2.61s (± 1.12%)2.59s (± 1.12%)-0.02s (- 0.69%)2.52s2.65s
Total Time11.36s (± 0.52%)11.27s (± 0.55%)-0.08s (- 0.74%)11.13s11.38s
Monaco - node (v10.16.3, x64)
Memory used356,547k (± 0.01%)356,594k (± 0.03%)+47k (+ 0.01%)356,373k356,783k
Parse Time1.56s (± 0.44%)1.55s (± 0.57%)-0.01s (- 0.58%)1.53s1.56s
Bind Time0.74s (± 0.68%)0.73s (± 0.65%)-0.00s (- 0.27%)0.72s0.74s
Check Time5.20s (± 0.38%)5.17s (± 0.78%)-0.04s (- 0.71%)5.07s5.24s
Emit Time3.12s (± 0.82%)3.12s (± 0.75%)-0.01s (- 0.16%)3.08s3.18s
Total Time10.61s (± 0.39%)10.56s (± 0.51%)-0.05s (- 0.46%)10.43s10.69s
TFS - node (v10.16.3, x64)
Memory used308,965k (± 0.02%)308,965k (± 0.02%)-0k (- 0.00%)308,817k309,142k
Parse Time1.22s (± 0.67%)1.21s (± 0.43%)-0.01s (- 0.66%)1.20s1.22s
Bind Time0.69s (± 0.69%)0.69s (± 0.72%)+0.00s (+ 0.29%)0.69s0.71s
Check Time4.70s (± 0.67%)4.67s (± 0.41%)-0.03s (- 0.55%)4.64s4.72s
Emit Time3.28s (± 1.06%)3.25s (± 0.80%)-0.03s (- 0.92%)3.19s3.30s
Total Time9.88s (± 0.62%)9.82s (± 0.34%)-0.06s (- 0.61%)9.76s9.91s
material-ui - node (v10.16.3, x64)
Memory used501,568k (± 0.01%)501,610k (± 0.01%)+41k (+ 0.01%)501,435k501,729k
Parse Time1.98s (± 0.38%)1.98s (± 0.44%)-0.00s (- 0.05%)1.96s2.00s
Bind Time0.65s (± 1.29%)0.65s (± 1.40%)+0.00s (+ 0.62%)0.63s0.67s
Check Time14.26s (± 0.80%)14.18s (± 0.40%)-0.09s (- 0.60%)14.06s14.29s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time16.89s (± 0.66%)16.81s (± 0.37%)-0.08s (- 0.50%)16.69s16.94s
Angular - node (v12.1.0, x64)
Memory used326,249k (± 0.02%)326,236k (± 0.02%)-13k (- 0.00%)326,061k326,374k
Parse Time1.91s (± 0.46%)1.91s (± 0.80%)0.00s ( 0.00%)1.87s1.93s
Bind Time0.81s (± 0.83%)0.81s (± 0.49%)+0.00s (+ 0.25%)0.80s0.82s
Check Time4.93s (± 0.41%)4.92s (± 0.45%)-0.01s (- 0.28%)4.86s4.98s
Emit Time5.97s (± 0.59%)5.96s (± 0.74%)-0.01s (- 0.25%)5.90s6.08s
Total Time13.61s (± 0.46%)13.59s (± 0.48%)-0.03s (- 0.21%)13.42s13.75s
Compiler-Unions - node (v12.1.0, x64)
Memory used191,506k (± 0.07%)190,446k (± 0.07%)-1,061k (- 0.55%)189,942k190,613k
Parse Time0.77s (± 0.84%)0.77s (± 0.76%)-0.00s (- 0.13%)0.76s0.78s
Bind Time0.52s (± 0.65%)0.52s (± 0.77%)-0.00s (- 0.76%)0.51s0.53s
Check Time6.90s (± 0.67%)6.89s (± 0.69%)-0.01s (- 0.17%)6.78s6.99s
Emit Time2.56s (± 0.93%)2.55s (± 0.92%)-0.01s (- 0.47%)2.50s2.61s
Total Time10.76s (± 0.45%)10.73s (± 0.53%)-0.03s (- 0.26%)10.57s10.85s
Monaco - node (v12.1.0, x64)
Memory used339,016k (± 0.01%)339,053k (± 0.02%)+37k (+ 0.01%)338,923k339,192k
Parse Time1.53s (± 0.55%)1.52s (± 0.57%)-0.01s (- 0.59%)1.50s1.54s
Bind Time0.72s (± 0.86%)0.71s (± 0.51%)-0.01s (- 0.97%)0.71s0.72s
Check Time5.03s (± 0.48%)4.97s (± 0.41%)-0.06s (- 1.27%)4.93s5.01s
Emit Time3.12s (± 0.58%)3.09s (± 0.59%)-0.03s (- 0.83%)3.06s3.14s
Total Time10.40s (± 0.28%)10.31s (± 0.27%)-0.10s (- 0.94%)10.24s10.37s
TFS - node (v12.1.0, x64)
Memory used293,124k (± 0.02%)293,068k (± 0.01%)-57k (- 0.02%)293,011k293,141k
Parse Time1.21s (± 1.19%)1.22s (± 0.73%)+0.01s (+ 0.66%)1.19s1.23s
Bind Time0.68s (± 0.87%)0.68s (± 0.70%)-0.00s (- 0.15%)0.67s0.69s
Check Time4.61s (± 0.46%)4.55s (± 0.50%)-0.06s (- 1.30%)4.49s4.59s
Emit Time3.16s (± 0.82%)3.15s (± 0.86%)-0.01s (- 0.44%)3.06s3.20s
Total Time9.66s (± 0.45%)9.59s (± 0.32%)-0.06s (- 0.67%)9.53s9.69s
material-ui - node (v12.1.0, x64)
Memory used479,599k (± 0.01%)479,336k (± 0.07%)-263k (- 0.05%)478,393k479,758k
Parse Time2.00s (± 0.43%)1.98s (± 0.38%)-0.01s (- 0.70%)1.97s2.00s
Bind Time0.64s (± 0.52%)0.64s (± 0.97%)-0.00s (- 0.16%)0.63s0.65s
Check Time12.84s (± 0.66%)13.00s (± 1.15%)+0.15s (+ 1.18%)12.71s13.31s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.48s (± 0.56%)15.62s (± 0.99%)+0.14s (+ 0.88%)15.34s15.94s
Angular - node (v14.15.1, x64)
Memory used324,912k (± 0.01%)324,931k (± 0.01%)+19k (+ 0.01%)324,872k325,042k
Parse Time1.90s (± 0.29%)1.91s (± 0.86%)+0.01s (+ 0.42%)1.88s1.96s
Bind Time0.84s (± 0.40%)0.85s (± 0.76%)+0.01s (+ 1.07%)0.84s0.86s
Check Time4.91s (± 0.35%)4.92s (± 0.24%)+0.00s (+ 0.08%)4.89s4.94s
Emit Time6.28s (± 0.68%)6.27s (± 0.55%)-0.01s (- 0.13%)6.22s6.39s
Total Time13.93s (± 0.39%)13.95s (± 0.27%)+0.01s (+ 0.09%)13.89s14.07s
Compiler-Unions - node (v14.15.1, x64)
Memory used191,073k (± 0.02%)190,058k (± 0.01%)-1,015k (- 0.53%)190,003k190,115k
Parse Time0.79s (± 0.62%)0.80s (± 0.86%)+0.00s (+ 0.25%)0.78s0.81s
Bind Time0.55s (± 1.01%)0.55s (± 0.00%)-0.00s (- 0.36%)0.55s0.55s
Check Time6.97s (± 0.52%)6.94s (± 0.20%)-0.03s (- 0.49%)6.91s6.97s
Emit Time2.54s (± 0.60%)2.53s (± 0.89%)-0.00s (- 0.08%)2.49s2.58s
Total Time10.85s (± 0.41%)10.81s (± 0.21%)-0.04s (- 0.39%)10.77s10.87s
Monaco - node (v14.15.1, x64)
Memory used338,095k (± 0.00%)338,053k (± 0.01%)-42k (- 0.01%)338,011k338,095k
Parse Time1.55s (± 0.43%)1.55s (± 0.44%)+0.00s (+ 0.26%)1.54s1.57s
Bind Time0.75s (± 0.89%)0.75s (± 0.67%)-0.00s (- 0.67%)0.74s0.76s
Check Time4.94s (± 0.50%)4.92s (± 0.15%)-0.02s (- 0.45%)4.90s4.93s
Emit Time3.15s (± 0.70%)3.14s (± 0.46%)-0.01s (- 0.35%)3.12s3.19s
Total Time10.39s (± 0.41%)10.36s (± 0.19%)-0.03s (- 0.31%)10.33s10.42s
TFS - node (v14.15.1, x64)
Memory used292,227k (± 0.01%)292,252k (± 0.01%)+25k (+ 0.01%)292,214k292,306k
Parse Time1.25s (± 0.93%)1.24s (± 1.16%)-0.01s (- 0.96%)1.21s1.27s
Bind Time0.72s (± 0.97%)0.71s (± 0.70%)-0.00s (- 0.56%)0.71s0.73s
Check Time4.56s (± 0.39%)4.57s (± 0.33%)+0.01s (+ 0.18%)4.54s4.60s
Emit Time3.24s (± 0.70%)3.24s (± 0.62%)-0.00s (- 0.06%)3.21s3.30s
Total Time9.78s (± 0.35%)9.77s (± 0.23%)-0.01s (- 0.07%)9.72s9.82s
material-ui - node (v14.15.1, x64)
Memory used477,936k (± 0.00%)477,719k (± 0.07%)-217k (- 0.05%)476,751k478,019k
Parse Time2.06s (± 0.69%)2.06s (± 0.55%)+0.00s (+ 0.15%)2.04s2.08s
Bind Time0.70s (± 0.83%)0.70s (± 0.52%)-0.00s (- 0.14%)0.69s0.70s
Check Time12.99s (± 0.70%)12.97s (± 0.79%)-0.02s (- 0.17%)12.76s13.17s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.74s (± 0.64%)15.72s (± 0.65%)-0.02s (- 0.14%)15.54s15.93s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-198-generic
Architecturex64
Available Memory16 GB
Available Memory5 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
BenchmarkNameIterations
Current4318310
Baselinemaster10

Developer Information:

Download Benchmark

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@typescript-bot
Copy link
Collaborator

@ahejlsberg
The results of the perf run you requested are in!

Here they are:

Comparison Report - master..43183

Metricmaster43183DeltaBestWorst
Angular - node (v14.15.1, x64)
Memory used324,912k (± 0.01%)324,935k (± 0.01%)+23k (+ 0.01%)324,842k325,009k
Parse Time1.90s (± 0.29%)1.91s (± 0.43%)+0.01s (+ 0.47%)1.89s1.93s
Bind Time0.84s (± 0.40%)0.85s (± 0.76%)+0.01s (+ 0.59%)0.84s0.86s
Check Time4.91s (± 0.35%)4.91s (± 0.65%)-0.00s (- 0.08%)4.85s4.99s
Emit Time6.28s (± 0.68%)6.27s (± 0.40%)-0.01s (- 0.19%)6.21s6.34s
Total Time13.93s (± 0.39%)13.93s (± 0.35%)-0.00s (- 0.02%)13.82s14.04s
Compiler-Unions - node (v14.15.1, x64)
Memory used191,073k (± 0.02%)190,043k (± 0.01%)-1,030k (- 0.54%)189,997k190,118k
Parse Time0.79s (± 0.62%)0.80s (± 0.86%)+0.00s (+ 0.25%)0.78s0.81s
Bind Time0.55s (± 1.01%)0.56s (± 0.89%)+0.00s (+ 0.72%)0.55s0.57s
Check Time6.97s (± 0.52%)7.02s (± 0.76%)+0.05s (+ 0.75%)6.94s7.20s
Emit Time2.54s (± 0.60%)2.54s (± 0.39%)+0.00s (+ 0.12%)2.52s2.56s
Total Time10.85s (± 0.41%)10.91s (± 0.55%)+0.06s (+ 0.55%)10.82s11.11s
Monaco - node (v14.15.1, x64)
Memory used338,095k (± 0.00%)338,063k (± 0.01%)-32k (- 0.01%)338,015k338,109k
Parse Time1.55s (± 0.43%)1.56s (± 0.73%)+0.01s (+ 0.52%)1.54s1.59s
Bind Time0.75s (± 0.89%)0.75s (± 0.80%)-0.00s (- 0.53%)0.74s0.76s
Check Time4.94s (± 0.50%)4.93s (± 0.42%)-0.01s (- 0.18%)4.88s4.97s
Emit Time3.15s (± 0.70%)3.15s (± 0.46%)-0.00s (- 0.03%)3.12s3.18s
Total Time10.39s (± 0.41%)10.38s (± 0.26%)-0.01s (- 0.07%)10.31s10.43s
TFS - node (v14.15.1, x64)
Memory used292,227k (± 0.01%)292,248k (± 0.01%)+21k (+ 0.01%)292,192k292,278k
Parse Time1.25s (± 0.93%)1.26s (± 0.89%)+0.01s (+ 0.56%)1.24s1.30s
Bind Time0.72s (± 0.97%)0.71s (± 1.06%)-0.01s (- 0.70%)0.70s0.74s
Check Time4.56s (± 0.39%)4.57s (± 0.35%)+0.00s (+ 0.09%)4.53s4.60s
Emit Time3.24s (± 0.70%)3.25s (± 0.56%)+0.00s (+ 0.09%)3.21s3.28s
Total Time9.78s (± 0.35%)9.79s (± 0.38%)+0.01s (+ 0.11%)9.73s9.92s
material-ui - node (v14.15.1, x64)
Memory used477,936k (± 0.00%)477,953k (± 0.00%)+16k (+ 0.00%)477,885k477,980k
Parse Time2.06s (± 0.69%)2.06s (± 0.60%)+0.01s (+ 0.34%)2.04s2.10s
Bind Time0.70s (± 0.83%)0.69s (± 1.19%)-0.00s (- 0.43%)0.68s0.71s
Check Time12.99s (± 0.70%)12.88s (± 0.34%)-0.11s (- 0.82%)12.79s12.97s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.74s (± 0.64%)15.64s (± 0.29%)-0.10s (- 0.65%)15.52s15.73s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-198-generic
Architecturex64
Available Memory16 GB
Available Memory5 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)
BenchmarkNameIterations
Current4318310
Baselinemaster10

Developer Information:

Download Benchmark

function getConstraintForReference(type: Type, reference: Identifier | ElementAccessExpression | PropertyAccessExpression | QualifiedName, checkMode: CheckMode | undefined){
// When the type of a reference is or contains an instantiable type with a union type constraint, and
// when the reference is in a constraint position (where it is known we'll obtain the apparent type) or
// has a contextual type containing no instantiables (meaning constraints will determine assignability),

Choose a reason for hiding this comment

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

Suggested change
// has a contextual type containing no instantiables (meaning constraints will determine assignability),
// has a contextual type containing no top-level instantiables (meaning constraints will determine assignability),

or

Suggested change
// has a contextual type containing no instantiables (meaning constraints will determine assignability),
// has a contextual type containing no immediate instantiables (meaning constraints will determine assignability),

@DanielRosenwasser
Copy link
Member

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 10, 2021

Heya @DanielRosenwasser, I've started to run the tarball bundle task on this PR at 1a695e9. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 10, 2021

Hey @DanielRosenwasser, 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/98224/artifacts?artifactName=tgz&fileId=266017171922858A31CD3EFD83E393EF6E56EB48D53ED8C01365E5A0113A6F5602&fileName=/typescript-4.3.0-insiders.20210310.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/[email protected]".;

@DanielRosenwasser
Copy link
Member

@ahejlsberg might be worth adding in the following test cases - f2 now works correctly.

interfaceBox<T>{item: T;}declarefunctionisBox(x: any): x is Box<unknown>;declarefunctionisUndefined(x: unknown): x is undefined;declarefunctionunbox<T>(x: Box<T>): T;functionf1<TextendsBox<T>|undefined>(x: T){if(isBox(x)){unbox(x);}}functionf2<TextendsBox<T>|undefined>(x: T){if(!isUndefined(x)){unbox(x);}}functionf3<TextendsBox<T>|undefined>(x: T){if(!isBox(x)){// errorunbox(x);}}functionf4<TextendsBox<T>|undefined>(x: T){if(isUndefined(x)){// errorunbox(x);}}

@ahejlsberg
Copy link
MemberAuthor

@DanielRosenwasser Will do.

@ahejlsberg
Copy link
MemberAuthor

ahejlsberg commented Mar 11, 2021

Performance looks to be unaffected. RWC test suite looks good too, only change is a couple of error messages that now show constraint types instead of generic types (as expected).

RaynalHugo added a commit to labelflow/labelflow that referenced this pull request Jul 23, 2021
chriskrycho added a commit to true-myth/true-myth that referenced this pull request Apr 22, 2022
TS 4.7 catches a class of error which 4.6 and earlier did not, courtesy of microsoft/TypeScript#43183: if the type passed does not implement `toString()`, it notices, because it no longer defaults to falling back to `{}`. Fixes#330
chriskrycho added a commit to true-myth/true-myth that referenced this pull request Apr 22, 2022
TS 4.7 catches a class of error which 4.6 and earlier did not, courtesy of microsoft/TypeScript#43183: if the type passed does not implement `toString()`, it notices, because it no longer defaults to falling back to `{}`. To resolve this, *loosen* the constraints on what is acceptable as input to `toString`, by making the implementation itself more robust. Doing so also fixes a bug with the output for `toString` when working with strings: previously if you had `Maybe("a string")`, the `toString` output would be `'Maybe(a string)'`; it is now `'Maybe("a string")'`. Fixes#330
chriskrycho added a commit to true-myth/true-myth that referenced this pull request Apr 22, 2022
TS 4.7 catches a class of error which 4.6 and earlier did not, courtesy of microsoft/TypeScript#43183: if the type passed does not implement `toString()`, it notices, because it no longer defaults to falling back to `{}`. To resolve this, *loosen* the constraints on what is acceptable as input to `toString`, by making the implementation itself more robust. Doing so also fixes a bug with the output for `toString` when working with strings: previously if you had `Maybe("a string")`, the `toString` output would be `'Maybe(a string)'`; it is now `'Maybe("a string")'`. Fixes#330
chriskrycho added a commit to true-myth/true-myth that referenced this pull request Apr 22, 2022
(cherry picked from commit 25adb1a) --- Original message: Add support for TypeScript 4.7 TS 4.7 catches a class of error which 4.6 and earlier did not, courtesy of microsoft/TypeScript#43183: if the type passed does not implement `toString()`, it notices, because it no longer defaults to falling back to `{}`. To resolve this, *loosen* the constraints on what is acceptable as input to `toString`, by making the implementation itself more robust. Doing so also fixes a bug with the output for `toString` when working with strings: previously if you had `Maybe("a string")`, the `toString` output would be `'Maybe(a string)'`; it is now `'Maybe("a string")'`. Fixes#330
@microsoftmicrosoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: TeamFor Backlog BugPRs that fix a backlog bugFor Milestone BugPRs that fix a bug with a specific milestone

Projects

None yet

9 participants

@ahejlsberg@typescript-bot@DanielRosenwasser@Farenheith@sandersn@weswigham@ARivas16@martinmunillas