Skip to content

Commit c2f435a

Browse files
remcohaszinghediet
andauthored
Fix global access of MonacoEnvironment (microsoft#248075)
Fix global access of MonacoEnvironment There are 3 ways to declare global variables in TypeScript. 1. A global `declare let`. 2. A global `declare var`. 3. Augmenting the global `Window`. There are 4 ways to access global variables in the browser. 1. Using a global identifier. 2. Using the `globalThis` object. 3. Using the `window` object. 4. Using the `self` object. Not all 3 types of global declarations work for all methods to access a global. | | `let` | `var` | `Window` | | ------------ | ----- | ----- | -------- | | global | ✓ | ✓ | | | `globalThis` | | ✓ | | | `window` | | ✓ | ✓ | | `self` | | ✓ | ✓ | So the proper way to declare the global `MonacoEnvironment`, is: ```ts declare global var MonacoEnvironment: Environment | undefined ``` https://www.typescriptlang.org/play/?#code/PQgEB4CcFMDNpgOwMbVAGwJYCMC8AiAEwHsBbfUYAPgFgAoew6ZdAQxlAHN1jtX1QAb3qhRGaABdQAGUkAuUAGcJkTIk4ixAN3agAauwXLV6+ptFqJCWK1SgA6mpIB3IebGjHiIyrUa6HgC+9MEMdGDcvPygtqiKivSyEvQGkPReZuHAoM5OxK6ckvS5iC4AdEnFec5lqVWl+WUZYWAlLkpFdG2NSaC4oADkA-XlqX2Dw13VTWrjQ5kRPHzoACoAFpiKXJ2Ry+ubFTtL-PuKtez0uycbZ830i1GrNx3JdFdPB73982-HH2djb6Td6nGaIOaTe7ZRTQdCwbavGFww6I2Gwc5pOhI9F3LIdOEvejYlEQolojGkrHkryU+jQAAeAAdiJApIJAkA --------- Co-authored-by: Henning Dieterichs <[email protected]>
1 parent 3a63678 commit c2f435a

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

build/gulpfile.editor.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,8 @@ function toExternalDTS(contents) {
116116
lines[i] = line.replace('declare namespace monaco.', 'export namespace ');
117117
}
118118

119-
if (line.indexOf('declare let MonacoEnvironment') === 0) {
120-
lines[i] = `declare global {\n let MonacoEnvironment: Environment | undefined;\n}`;
121-
}
122-
123-
if (line.indexOf('\tMonacoEnvironment?') === 0) {
124-
lines[i] = ` MonacoEnvironment?: Environment | undefined;`;
119+
if (line.indexOf('declare var MonacoEnvironment') === 0) {
120+
lines[i] = `declare global {\n var MonacoEnvironment: Environment | undefined;\n}`;
125121
}
126122
}
127123
return lines.join('\n').replace(/\n\n\n+/g, '\n\n');

build/monaco/monaco.d.ts.recipe

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
declare let MonacoEnvironment: monaco.Environment | undefined;
7-
8-
interface Window {
9-
MonacoEnvironment?: monaco.Environment | undefined;
10-
}
6+
// eslint-disable-next-line no-var
7+
declare var MonacoEnvironment: monaco.Environment | undefined;
118

129
declare namespace monaco {
1310

src/vs/monaco.d.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
declare let MonacoEnvironment: monaco.Environment | undefined;
7-
8-
interface Window {
9-
MonacoEnvironment?: monaco.Environment | undefined;
10-
}
6+
// eslint-disable-next-line no-var
7+
declare var MonacoEnvironment: monaco.Environment | undefined;
118

129
declare namespace monaco {
1310

0 commit comments

Comments
 (0)