mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-15 14:05:47 -05:00
fix error on globalThis type extend (#30460)
* Add test for extend globalThis * Fix compile aborting
This commit is contained in:
committed by
Nathan Shively-Sanders
parent
d0646a629a
commit
18b8625ef8
@@ -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) {
|
||||
|
||||
24
tests/baselines/reference/extendGlobalThis.js
Normal file
24
tests/baselines/reference/extendGlobalThis.js
Normal file
@@ -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("-"));
|
||||
30
tests/baselines/reference/extendGlobalThis.symbols
Normal file
30
tests/baselines/reference/extendGlobalThis.symbols
Normal file
@@ -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, --, --))
|
||||
|
||||
37
tests/baselines/reference/extendGlobalThis.types
Normal file
37
tests/baselines/reference/extendGlobalThis.types
Normal file
@@ -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[]
|
||||
>"-" : "-"
|
||||
|
||||
14
tests/cases/compiler/extendGlobalThis.ts
Normal file
14
tests/cases/compiler/extendGlobalThis.ts
Normal file
@@ -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("-"));
|
||||
Reference in New Issue
Block a user