You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected behavior:
Type checking of this single file completes in the order of milliseconds.
A real world example of this issue has been reported in the Angular repo for code generated by the template type checker: angular/angular#33532. Angular has a code generator that emits TypeScript code to typecheck Angular templates.
Actual behavior:
Each additional if-statement is causing the type checking phase to roughly double in time. The above sample takes ~2.9s in the "Check" phase, as reported in the diagnostics report:
TypeScript Version: 3.8.0-dev.20191119
Also reproduceable in earlier versions. A quick scan through older versions shows TS 2.0 has a check time of 0.2s, which regressed to 1.9s in TS 2.1.
Search Terms: performance, union types, enum, flow analysis, type narrowing
Code
Expected behavior:
Type checking of this single file completes in the order of milliseconds.
A real world example of this issue has been reported in the Angular repo for code generated by the template type checker: angular/angular#33532. Angular has a code generator that emits TypeScript code to typecheck Angular templates.
Actual behavior:
Each additional if-statement is causing the type checking phase to roughly double in time. The above sample takes ~2.9s in the "Check" phase, as reported in the diagnostics report:
Adding one additional
if
statement increases the Check time to ~6.5s:These options do resolve the exponential slowdown:
choice
orchoiceOne
toany
choiceOne
into the if-statementsThese options do not resolve the exponential slowdown:
Choice.One
Note that all these options do reduce the time, however adding additional if-statements still shows exponential slowdown.
Playground Link:
Terminal reproduction to get insight in timings:
Source code for
sample.ts
is found above, under Code.Related Issues: Not really
The text was updated successfully, but these errors were encountered: