Skip to content

isolatedModules error on global shadowed by imported type - #56732

Merged
Andrew Branch (andrewbranch) merged 3 commits into
microsoft:mainfrom
frigus02:shadow-type
Dec 13, 2023
Merged

isolatedModules error on global shadowed by imported type#56732
Andrew Branch (andrewbranch) merged 3 commits into
microsoft:mainfrom
frigus02:shadow-type

Conversation

@frigus02

Copy link
Copy Markdown
Contributor

Fixes#56521

I took inspiration from #56354, which seems very similar.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! I think this is pretty close.

Comment threadsrc/compiler/checker.ts Outdated
Comment threadsrc/compiler/checker.ts Outdated
@frigus02

Copy link
Copy Markdown
ContributorAuthor

Thanks for the quick review! I think I addressed your comments.

(Not sure about the comment resolving etiquette here. I hope me resolving them is fine?)

@frigus02

Copy link
Copy Markdown
ContributorAuthor

The new error currently incorrectly fires for the following Node.js code:

import{Console}from"node:console";constc: Console=newConsole();

That's because console.Console is indeed a global. But it's re-exported in the module node:console. Importantly, though, the global is console.Console, not Console, so the import is necessary.

Node.js typings for reference: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/420d2ceb50f728aa715da1250a2a9f27760a640c/types/node/console.d.ts#L412

Weirdly there is no error for this code:

import{Console}from"node:console";newConsole();

I'm going to look into that tomorrow. If you have any ideas, I'd definitely appreciate your help, Andrew Branch (@andrewbranch).

@frigus02

Copy link
Copy Markdown
ContributorAuthor

Aha. I think SymbolFlags.Value is not a single bit. I just copied the check from a few lines up. But I think I need to use (meaning & SymbolFlags.Value) === SymbolFlags.Value here. I'll test some more tomorrow and update the code and tests.

@andrewbranch

Copy link
Copy Markdown
Member

Oh, good catch. Yeah, I think something like that should work, or alternatively a lookup with SymbolFlags.Type | SymbolFlags.NamespaceModule

@frigus02

Copy link
Copy Markdown
ContributorAuthor

As far as I can tell this looks good now. I did not use SymbolFlags.Type | SymbolFlags.NamespaceModule, yet. But happy to switch to that if you prefer.

@andrewbranch

Copy link
Copy Markdown
Member

@typescript-bot

TypeScript Bot (typescript-bot) commented Dec 13, 2023

Copy link
Copy Markdown
Contributor

Heya Andrew Branch (@andrewbranch), I've started to run the regular perf test suite on this PR at fa03480. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Dec 13, 2023

Copy link
Copy Markdown
Contributor

Heya Andrew Branch (@andrewbranch), I've started to run the diff-based top-repos suite on this PR at fa03480. You can monitor the build here.

Update: The results are in!

@typescript-bot

Copy link
Copy Markdown
Contributor

Andrew Branch (@andrewbranch)
The results of the perf run you requested are in!

Here they are:

Compiler

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Angular - node (v18.15.0, x64)
Memory used295,410k (± 0.01%)295,395k (± 0.01%)~295,380k295,420kp=0.261 n=6
Parse Time2.64s (± 0.46%)2.64s (± 0.41%)~2.62s2.65sp=0.432 n=6
Bind Time0.82s (± 0.00%)0.82s (± 0.50%)~0.82s0.83sp=0.405 n=6
Check Time8.14s (± 0.39%)8.14s (± 0.29%)~8.11s8.18sp=0.936 n=6
Emit Time7.08s (± 0.15%)7.08s (± 0.36%)~7.05s7.12sp=0.745 n=6
Total Time18.69s (± 0.18%)18.69s (± 0.25%)~18.61s18.75sp=0.936 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used195,329k (± 1.54%)194,823k (± 1.49%)~191,383k197,488kp=1.000 n=6
Parse Time1.35s (± 1.21%)1.36s (± 1.08%)~1.34s1.38sp=0.677 n=6
Bind Time0.72s (± 0.00%)0.72s (± 0.00%)~0.72s0.72sp=1.000 n=6
Check Time9.26s (± 0.44%)9.26s (± 0.35%)~9.20s9.29sp=1.000 n=6
Emit Time2.63s (± 0.46%)2.64s (± 0.65%)~2.62s2.67sp=0.154 n=6
Total Time13.96s (± 0.38%)13.97s (± 0.34%)~13.89s14.02sp=0.747 n=6
Monaco - node (v18.15.0, x64)
Memory used347,379k (± 0.01%)347,356k (± 0.01%)~347,333k347,386kp=0.078 n=6
Parse Time2.45s (± 0.40%)2.45s (± 0.40%)~2.44s2.47sp=1.000 n=6
Bind Time0.93s (± 0.56%)0.92s (± 0.56%)~0.92s0.93sp=0.311 n=6
Check Time6.90s (± 0.20%)6.89s (± 0.31%)~6.87s6.92sp=0.566 n=6
Emit Time4.05s (± 0.48%)4.05s (± 0.44%)~4.02s4.07sp=0.808 n=6
Total Time14.32s (± 0.22%)14.32s (± 0.24%)~14.29s14.37sp=0.936 n=6
TFS - node (v18.15.0, x64)
Memory used302,640k (± 0.00%)302,650k (± 0.00%)~302,640k302,661kp=0.230 n=6
Parse Time2.00s (± 0.74%)1.99s (± 0.49%)~1.98s2.01sp=0.440 n=6
Bind Time1.00s (± 0.98%)1.01s (± 1.25%)~0.99s1.02sp=0.270 n=6
Check Time6.28s (± 0.29%)6.27s (± 0.46%)~6.23s6.30sp=0.746 n=6
Emit Time3.59s (± 0.89%)3.59s (± 0.66%)~3.56s3.63sp=0.683 n=6
Total Time12.86s (± 0.31%)12.86s (± 0.13%)~12.84s12.88sp=0.687 n=6
material-ui - node (v18.15.0, x64)
Memory used506,788k (± 0.00%)506,806k (± 0.01%)~506,751k506,841kp=0.173 n=6
Parse Time2.58s (± 0.47%)2.58s (± 0.67%)~2.56s2.61sp=0.558 n=6
Bind Time0.99s (± 1.28%)0.98s (± 0.77%)~0.97s0.99sp=0.301 n=6
Check Time16.87s (± 0.37%)16.90s (± 0.39%)~16.83s17.00sp=0.518 n=6
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)~0.00s0.00sp=1.000 n=6
Total Time20.43s (± 0.27%)20.46s (± 0.36%)~20.40s20.59sp=0.520 n=6
xstate - node (v18.15.0, x64)
Memory used512,813k (± 0.01%)512,847k (± 0.01%)~512,780k512,933kp=0.471 n=6
Parse Time3.27s (± 0.19%)3.27s (± 0.19%)~3.26s3.28sp=1.000 n=6
Bind Time1.54s (± 0.36%)1.54s (± 0.49%)~1.53s1.55sp=0.137 n=6
Check Time2.81s (± 0.43%)2.82s (± 0.73%)~2.80s2.86sp=0.367 n=6
Emit Time0.07s (± 0.00%)0.07s (± 5.69%)~0.07s0.08sp=0.405 n=6
Total Time7.69s (± 0.19%)7.71s (± 0.26%)~7.69s7.74sp=0.252 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

tsserver

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Compiler-UnionsTSServer - node (v18.15.0, x64)
Req 1 - updateOpen2,340ms (± 0.36%)2,338ms (± 0.45%)~2,327ms2,352msp=0.687 n=6
Req 2 - geterr5,414ms (± 1.22%)5,457ms (± 1.58%)~5,359ms5,551msp=0.199 n=6
Req 3 - references323ms (± 0.34%)324ms (± 0.87%)~320ms326msp=0.516 n=6
Req 4 - navto278ms (± 1.27%)277ms (± 1.39%)~273ms280msp=0.337 n=6
Req 5 - completionInfo count1,356 (± 0.00%)1,356 (± 0.00%)~1,3561,356p=1.000 n=6
Req 5 - completionInfo86ms (± 6.36%)87ms (± 5.86%)~82ms92msp=0.738 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen2,487ms (± 0.64%)2,482ms (± 1.35%)~2,435ms2,533msp=0.810 n=6
Req 2 - geterr4,086ms (± 1.54%)4,096ms (± 1.46%)~4,048ms4,215msp=0.376 n=6
Req 3 - references344ms (± 1.16%)341ms (± 1.40%)~337ms348msp=0.627 n=6
Req 4 - navto285ms (± 0.26%)285ms (± 0.29%)~284ms286msp=0.306 n=6
Req 5 - completionInfo count1,518 (± 0.00%)1,518 (± 0.00%)~1,5181,518p=1.000 n=6
Req 5 - completionInfo87ms (± 5.20%)87ms (± 5.73%)~77ms90msp=0.607 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen2,593ms (± 0.72%)2,600ms (± 0.85%)~2,571ms2,632msp=0.471 n=6
Req 2 - geterr1,698ms (± 1.88%)1,699ms (± 1.33%)~1,672ms1,729msp=1.000 n=6
Req 3 - references112ms (± 9.92%)122ms (± 2.29%)~117ms125msp=0.060 n=6
Req 4 - navto365ms (± 0.56%)366ms (± 0.21%)~365ms367msp=0.319 n=6
Req 5 - completionInfo count2,073 (± 0.00%)2,073 (± 0.00%)~2,0732,073p=1.000 n=6
Req 5 - completionInfo307ms (± 2.21%)306ms (± 2.16%)~295ms314msp=0.872 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • CompilerTSServer - node (v18.15.0, x64)
  • Compiler-UnionsTSServer - node (v18.15.0, x64)
  • xstateTSServer - node (v18.15.0, x64)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Startup

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
tsc-startup - node (v18.15.0, x64)
Execution time152.78ms (± 0.20%)152.73ms (± 0.18%)~151.66ms157.07msp=0.304 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time228.54ms (± 0.19%)228.35ms (± 0.17%)-0.19ms (- 0.08%)227.09ms235.35msp=0.000 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time229.62ms (± 0.20%)229.64ms (± 0.20%)~227.79ms236.45msp=1.000 n=600
typescript-startup - node (v18.15.0, x64)
Execution time229.48ms (± 0.19%)229.35ms (± 0.16%)-0.12ms (- 0.05%)228.07ms232.75msp=0.020 n=600
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • tsc-startup - node (v18.15.0, x64)
  • tsserver-startup - node (v18.15.0, x64)
  • tsserverlibrary-startup - node (v18.15.0, x64)
  • typescript-startup - node (v18.15.0, x64)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Developer Information:

Download Benchmarks

@typescript-bot

Copy link
Copy Markdown
Contributor

Andrew Branch (@andrewbranch) Here are the results of running the top-repos suite comparing main and refs/pull/56732/merge:

Everything looks good!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@andrewbranch
Andrew Branch (andrewbranch) merged commit ba9eddb into microsoft:mainDec 13, 2023
@frigus02
Jan Kühle (frigus02) deleted the shadow-type branch December 13, 2023 18:35
@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 16, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Milestone BugPRs that fix a bug with a specific milestone

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect ts.transpileModule() emit when imported type shadows type but not constructor of global symbol

3 participants

@frigus02@andrewbranch@typescript-bot