Skip to content

Commit aba0b70

Browse files
authored
Allow circular umd-merged-with-augmentation refs to resolve to the module as intended (microsoft#29335)
1 parent 76f444e commit aba0b70

5 files changed

+151
-0
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5431,6 +5431,10 @@ namespace ts {
54315431

54325432
// Handle variable, parameter or property
54335433
if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
5434+
// Symbol is property of some kind that is merged with something - should use `getTypeOfFuncClassEnumModule` and not `getTypeOfVariableOrParameterOrProperty`
5435+
if (symbol.flags & SymbolFlags.ValueModule) {
5436+
return getTypeOfFuncClassEnumModule(symbol);
5437+
}
54345438
return errorType;
54355439
}
54365440
let type: Type | undefined;
@@ -5486,6 +5490,10 @@ namespace ts {
54865490
}
54875491

54885492
if (!popTypeResolution()) {
5493+
// Symbol is property of some kind that is merged with something - should use `getTypeOfFuncClassEnumModule` and not `getTypeOfVariableOrParameterOrProperty`
5494+
if (symbol.flags & SymbolFlags.ValueModule) {
5495+
return getTypeOfFuncClassEnumModule(symbol);
5496+
}
54895497
type = reportCircularityError(symbol);
54905498
}
54915499
return type;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [tests/cases/compiler/umdNamespaceMergedWithGlobalAugmentationIsNotCircular.ts] ////
2+
3+
//// [global.d.ts]
4+
declare global {
5+
const React: typeof import("./module");
6+
}
7+
8+
export { };
9+
10+
//// [module.d.ts]
11+
export = React;
12+
export as namespace React;
13+
14+
declare namespace React {
15+
function createRef(): any;
16+
}
17+
18+
//// [some_module.ts]
19+
export { };
20+
React.createRef;
21+
22+
//// [emits.ts]
23+
console.log("hello");
24+
React.createRef;
25+
26+
//// [some_module.js]
27+
React.createRef;
28+
//// [emits.js]
29+
"use strict";
30+
console.log("hello");
31+
React.createRef;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
=== tests/cases/compiler/global.d.ts ===
2+
declare global {
3+
>global : Symbol(global, Decl(global.d.ts, 0, 0))
4+
5+
const React: typeof import("./module");
6+
>React : Symbol(React, Decl(module.d.ts, 1, 26), Decl(global.d.ts, 1, 9))
7+
}
8+
9+
export { };
10+
11+
=== tests/cases/compiler/module.d.ts ===
12+
export = React;
13+
>React : Symbol(React, Decl(module.d.ts, 1, 26))
14+
15+
export as namespace React;
16+
>React : Symbol(React, Decl(module.d.ts, 0, 15))
17+
18+
declare namespace React {
19+
>React : Symbol(React, Decl(module.d.ts, 1, 26), Decl(global.d.ts, 1, 9))
20+
21+
function createRef(): any;
22+
>createRef : Symbol(createRef, Decl(module.d.ts, 3, 25))
23+
}
24+
25+
=== tests/cases/compiler/some_module.ts ===
26+
export { };
27+
React.createRef;
28+
>React.createRef : Symbol(React.createRef, Decl(module.d.ts, 3, 25))
29+
>React : Symbol(React, Decl(module.d.ts, 1, 26), Decl(global.d.ts, 1, 9))
30+
>createRef : Symbol(React.createRef, Decl(module.d.ts, 3, 25))
31+
32+
=== tests/cases/compiler/emits.ts ===
33+
console.log("hello");
34+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
35+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
36+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
37+
38+
React.createRef;
39+
>React.createRef : Symbol(React.createRef, Decl(module.d.ts, 3, 25))
40+
>React : Symbol(React, Decl(module.d.ts, 1, 26), Decl(global.d.ts, 1, 9))
41+
>createRef : Symbol(React.createRef, Decl(module.d.ts, 3, 25))
42+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
=== tests/cases/compiler/global.d.ts ===
2+
declare global {
3+
>global : typeof global
4+
5+
const React: typeof import("./module");
6+
>React : typeof React
7+
}
8+
9+
export { };
10+
11+
=== tests/cases/compiler/module.d.ts ===
12+
export = React;
13+
>React : typeof React
14+
15+
export as namespace React;
16+
>React : typeof React
17+
18+
declare namespace React {
19+
>React : typeof React
20+
21+
function createRef(): any;
22+
>createRef : () => any
23+
}
24+
25+
=== tests/cases/compiler/some_module.ts ===
26+
export { };
27+
React.createRef;
28+
>React.createRef : () => any
29+
>React : typeof React
30+
>createRef : () => any
31+
32+
=== tests/cases/compiler/emits.ts ===
33+
console.log("hello");
34+
>console.log("hello") : void
35+
>console.log : (message?: any, ...optionalParams: any[]) => void
36+
>console : Console
37+
>log : (message?: any, ...optionalParams: any[]) => void
38+
>"hello" : "hello"
39+
40+
React.createRef;
41+
>React.createRef : () => any
42+
>React : typeof React
43+
>createRef : () => any
44+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// @strict: true
2+
// @module: esnext
3+
// @moduleResolution: node
4+
// @target: es2018
5+
// @filename: global.d.ts
6+
declare global {
7+
const React: typeof import("./module");
8+
}
9+
10+
export { };
11+
12+
// @filename: module.d.ts
13+
export = React;
14+
export as namespace React;
15+
16+
declare namespace React {
17+
function createRef(): any;
18+
}
19+
20+
// @filename: some_module.ts
21+
export { };
22+
React.createRef;
23+
24+
// @filename: emits.ts
25+
console.log("hello");
26+
React.createRef;

0 commit comments

Comments
 (0)