diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 12dccd8bc64..8ef07866299 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -27980,8 +27980,8 @@ namespace ts { // The following checks only apply on a non-ambient instantiated module declaration. if (symbol.flags & SymbolFlags.ValueModule - && symbol.declarations.length > 1 && !inAmbientContext + && symbol.declarations.length > 1 && isInstantiatedModule(node, !!compilerOptions.preserveConstEnums || !!compilerOptions.isolatedModules)) { const firstNonAmbientClassOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); if (firstNonAmbientClassOrFunc) { diff --git a/tests/baselines/reference/extendGlobalThis.js b/tests/baselines/reference/extendGlobalThis.js new file mode 100644 index 00000000000..c8b73a0c39f --- /dev/null +++ b/tests/baselines/reference/extendGlobalThis.js @@ -0,0 +1,24 @@ +//// [tests/cases/compiler/extendGlobalThis.ts] //// + +//// [extension.d.ts] +declare global { + namespace globalThis { + var test: string; + } +} + +export {} + +//// [index.ts] +import "./extention"; + +globalThis.tests = "a-b"; +console.log(globalThis.test.split("-")); + + +//// [index.js] +"use strict"; +exports.__esModule = true; +require("./extention"); +globalThis.tests = "a-b"; +console.log(globalThis.test.split("-")); diff --git a/tests/baselines/reference/extendGlobalThis.symbols b/tests/baselines/reference/extendGlobalThis.symbols new file mode 100644 index 00000000000..944d7b23715 --- /dev/null +++ b/tests/baselines/reference/extendGlobalThis.symbols @@ -0,0 +1,30 @@ +=== tests/cases/compiler/extension.d.ts === +declare global { +>global : Symbol(global, Decl(extension.d.ts, 0, 0)) + + namespace globalThis { +>globalThis : Symbol(globalThis) + + var test: string; +>test : Symbol(test, Decl(extension.d.ts, 2, 11)) + } +} + +export {} + +=== tests/cases/compiler/index.ts === +import "./extention"; + +globalThis.tests = "a-b"; +>globalThis : Symbol(globalThis) + +console.log(globalThis.test.split("-")); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>globalThis.test.split : Symbol(String.split, Decl(lib.es5.d.ts, --, --)) +>globalThis.test : Symbol(test, Decl(extension.d.ts, 2, 11)) +>globalThis : Symbol(globalThis) +>test : Symbol(test, Decl(extension.d.ts, 2, 11)) +>split : Symbol(String.split, Decl(lib.es5.d.ts, --, --)) + diff --git a/tests/baselines/reference/extendGlobalThis.types b/tests/baselines/reference/extendGlobalThis.types new file mode 100644 index 00000000000..88fe0462d65 --- /dev/null +++ b/tests/baselines/reference/extendGlobalThis.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/extension.d.ts === +declare global { +>global : typeof global + + namespace globalThis { +>globalThis : typeof globalThis + + var test: string; +>test : string + } +} + +export {} + +=== tests/cases/compiler/index.ts === +import "./extention"; + +globalThis.tests = "a-b"; +>globalThis.tests = "a-b" : "a-b" +>globalThis.tests : any +>globalThis : typeof globalThis +>tests : any +>"a-b" : "a-b" + +console.log(globalThis.test.split("-")); +>console.log(globalThis.test.split("-")) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>globalThis.test.split("-") : string[] +>globalThis.test.split : (separator: string | RegExp, limit?: number) => string[] +>globalThis.test : string +>globalThis : typeof globalThis +>test : string +>split : (separator: string | RegExp, limit?: number) => string[] +>"-" : "-" + diff --git a/tests/cases/compiler/extendGlobalThis.ts b/tests/cases/compiler/extendGlobalThis.ts new file mode 100644 index 00000000000..1ad9f0552b4 --- /dev/null +++ b/tests/cases/compiler/extendGlobalThis.ts @@ -0,0 +1,14 @@ +// @filename: extension.d.ts +declare global { + namespace globalThis { + var test: string; + } +} + +export {} + +// @filename: index.ts +import "./extention"; + +globalThis.tests = "a-b"; +console.log(globalThis.test.split("-"));