GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add flag to allow access to UMD globals from modules by andrewbranch · Pull Request #30776 · microsoft/TypeScript

Conversation

@andrewbranch

@andrewbranch Andrew Branch (andrewbranch) commented Apr 5, 2019

Copy link
Copy Markdown
Member

Closes #10178.

A summary, since the issue discussion is quite long: the allowUmdGlobalAccess flag will allow accessing a global defined in a UMD module from anywhere, including from modules. This could potentially be unsafe since not all UMD modules define a global in the presence of a module system, but under some circumstances you really might need the ability. E.g. in a browser environment where one UMD module loads before require.js, that module will only be available as a global. So, this flag is an escape hatch for users stuck in scenarios like that.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mihailik, kohlmannj, trusktr, MichielCornilleESC, and traxium reacted with thumbs up emoji trusktr and MichielCornilleESC reacted with hooray emoji mihailik, overlineink, donatj, and kohlmannj reacted with heart emoji
All reactions
  • 👍 5 reactions
  • 🎉 2 reactions
  • ❤️ 4 reactions
@andrewbranch Andrew Branch (andrewbranch) added the Add a Flag label Apr 5, 2019
@andrewbranch
Andrew Branch (andrewbranch) requested review from Daniel Rosenwasser (DanielRosenwasser), Nathan Shively-Sanders (sandersn) and Sheetal Nandi (sheetalkamat) April 5, 2019 18:57
sheetalkamat
Sheetal Nandi (sheetalkamat) requested changes Apr 5, 2019
View reviewed changes
Comment thread src/compiler/commandLineParser.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/compiler/checker.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread tests/cases/conformance/externalModules/umd9.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@andrewbranch
Andrew Branch (andrewbranch) requested a review from Sheetal Nandi (sheetalkamat) April 5, 2019 21:37
@RyanCavanaugh

Ryan Cavanaugh (RyanCavanaugh) commented Apr 5, 2019

Copy link
Copy Markdown
Member

Need to revert submodule updates, otherwise LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@weswigham

Wesley Wigham (weswigham) commented Apr 6, 2019 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This flag quite literally just suppresses the error since we already "do the right thing" in the presence of the error with respect to types. Should we not just concede to community demand and add a generalized "suppressions": ["TS2686"]-type compiler option? Because that's all this new command is an alias for. (And I imagine if we do the more generalized option we can be smart and still return the errors as suggestions, which we do not (yet?) do here)

saschanaz, DanielRX, and aaronbeall reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

weswigham
Wesley Wigham (weswigham) reviewed Apr 6, 2019
View reviewed changes
Comment thread src/compiler/checker.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@andrewbranch

Andrew Branch (andrewbranch) commented Apr 6, 2019

Copy link
Copy Markdown
Member Author

Wesley Wigham (@weswigham) good point. I'm sure I'm missing some prior discussion here, but aren't there some error codes that are virtually unsuppressible, or would have horrifying consequences if suppressed? This particular error is a great example of something that would work, but I'm thinking about e.g. parser errors... suppressing a diagnostic from parseExpectedToken would essentially allow people to invent their own more concise non-standard syntax; in other cases, invalid syntax could parse as a totally different syntax tree than a user is expecting, without surfacing any diagnostics.

I guess a better summary of what I'm asking is—while I don't personally feel the need to try to force users into writing better TypeScript against their will, would a feature like that, on average, actually result in a better user experience? Or would it inadvertently wreak more havoc than solve problems?

As a newbie, this is a legitimate question, not rhetorical, and I'd happily defer to the team's consensus.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@weswigham

Wesley Wigham (weswigham) commented Apr 6, 2019

Copy link
Copy Markdown
Member

or would have horrifying consequences if suppressed?

We already have // @ts-ignore comments that let you suppress anything, sooooooo

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ajafff

Klaus Meinhardt (ajafff) commented Apr 6, 2019

Copy link
Copy Markdown
Contributor

We already have // ts-ignore comments that let you suppress anything

IIRC that's not the case. It doesn't suppress parse errors and declaration emit diagnostics (don't know about binder diagnostics)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@weswigham

Wesley Wigham (weswigham) commented Apr 6, 2019

Copy link
Copy Markdown
Member

It doesn't suppress parse errors and declaration emit diagnostics (don't know about binder diagnostics)

We can exclude those from the errors we'll suppress, too, then. I'm just thinking that adding a suppressions argument that acts like a ts-ignore for all errors of a specific type is probably more general, and I know I've seen requests for it (much as I personally loathe the idea of suppressing any of our errors).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) removed the Add a Flag label Apr 8, 2019
Andrew Branch (andrewbranch) added 8 commits April 8, 2019 09:46
@andrewbranch
Add allowUmdGlobalAccess flag
2ee93bf
@andrewbranch
Add test
6d1d680
@andrewbranch
Don’t emit diagnostic accessing UMD globals from modules when flag is…
11e4516
… set
@andrewbranch
Add baselines for UMD global access
57b9e38
@andrewbranch
Add period to compiler flag description to match others
28b21df
@andrewbranch
Update baselines with new flag
6c06507
@andrewbranch
Add affectsSemanticDiagnostics to flag (and move to right spot)
98cd89f
@andrewbranch
Use suggestion instead of ignoring UMD global access
786753d
@andrewbranch
Andrew Branch (andrewbranch) force-pushed the feature/10178 branch from 1647187 to 786753d Compare April 8, 2019 16:47
RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh) approved these changes Apr 9, 2019
View reviewed changes
sheetalkamat
Sheetal Nandi (sheetalkamat) reviewed Apr 11, 2019
View reviewed changes
Comment thread src/compiler/checker.ts
const merged = getMergedSymbol(result);
if (length(merged.declarations) && every(merged.declarations, d => isNamespaceExportDeclaration(d) || isSourceFile(d) && !!d.symbol.globalExports)) {
error(errorLocation!, Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, unescapeLeadingUnderscores(name)); // TODO: GH#18217
errorOrSuggestion(!compilerOptions.allowUmdGlobalAccess, errorLocation!, Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, unescapeLeadingUnderscores(name));

@sheetalkamat Sheetal Nandi (sheetalkamat) Apr 11, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Should this diagnostic change to additionally mention or enable allowUmdGlobalAccess if?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@andrewbranch Andrew Branch (andrewbranch) Apr 18, 2019

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Since this is errorOrSuggestion based on the compiler option, we would have to use two different messages depending on the value of the option (since users with it enabled should not see a message that says "Enable the 'allowUmdGlobalAccess' compiler option")... do you think that's worth it?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) Apr 18, 2019

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'd leave as-is. In general for errors we think are usually correct, we try not to mention commandline flags to disable the error, since people will often try disabling the error before even checking if their code works or not

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

weswigham reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@andrewbranch
Andrew Branch (andrewbranch) merged commit b6a0988 into microsoft:master Apr 19, 2019
@andrewbranch
Andrew Branch (andrewbranch) deleted the feature/10178 branch April 19, 2019 01:05
mihailik
mihailik reviewed Apr 23, 2019
View reviewed changes
Comment thread tests/cases/conformance/externalModules/umd9.ts
export as namespace Foo;

// @filename: a.ts
/// <reference path="foo.d.ts" />

@mihailik mihailik Apr 23, 2019

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Is this a requirement in this file?

Given the original issue #1078 is sooo convoluted, it may be well worth a bit of write-up how this new feature works.

P.S. I have a feeling it may be extremely useful in some scenarios I am involved, but need a more defined behaviour/usage/spec to know for sure.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@andrewbranch Andrew Branch (andrewbranch) Apr 24, 2019

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You're right, the original issue is a lot to absorb, but this “feature” is actually quite simple. All it does is suppress a particular error message. This one:

image

The triple slash reference isn't related to this feature at all; it's related to the @noImplicitReferences option which is just a configuration for our test harness.

Does that clear things up, or do you have any additional specific questions?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mihailik, overlineink, paknudsen, jorroll, orta, and yolilufei reacted with thumbs up emoji
All reactions
  • 👍 6 reactions

@mihailik mihailik Apr 25, 2019

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks, all clear.

It's awesome: from complex to trivial in a couple sentences.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

andrewbranch and overlineink reacted with heart emoji
All reactions
  • ❤️ 2 reactions
@andrewbranch Andrew Branch (andrewbranch) mentioned this pull request May 23, 2019
Add new TypeScript compiler option 'allowUmdGlobalAccess' to tsconfig and jsconfig SchemaStore/schemastore#699
Merged
tqma113
tqma113 reviewed Sep 30, 2019
View reviewed changes

@tqma113 tqma113 left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM, That's great.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@shobhitsinghal624 Shobhit Singhal (shobhitsinghal624) mentioned this pull request May 7, 2020
[tsserver 2686] [I] '_' refers to a UMD global, but the current file is a module. neoclide/coc-tsserver#149
Closed
@taoliujun taoliujun (taoliujun) mentioned this pull request Nov 27, 2023
关于tsconfig.json,最后更新2023/11月... taoliujun/blog#23
Open
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@weswigham Wesley Wigham (weswigham) weswigham left review comments
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) RyanCavanaugh approved these changes
@sheetalkamat Sheetal Nandi (sheetalkamat) sheetalkamat requested changes
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Awaiting requested review from DanielRosenwasser
@sandersn Nathan Shively-Sanders (sandersn) Awaiting requested review from sandersn
+2 more reviewers
@mihailik mihailik mihailik left review comments
@tqma113 tqma113 tqma113 left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Consider allowing access to UMD globals from modules

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@andrewbranch @RyanCavanaugh @weswigham @ajafff @mihailik @sheetalkamat @tqma113 @DanielRosenwasser
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.