Skip to content

Commit 4ee013d

Browse files
committed
Fix merging of JS value & TS type decl
Fixes #38383
1 parent 077a2a9 commit 4ee013d

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7870,7 +7870,7 @@ namespace ts {
78707870
(resolvedSymbol || symbol).exports!.forEach((s, name) => {
78717871
const exportedMember = members.get(name)!;
78727872
if (exportedMember && exportedMember !== s) {
7873-
if (s.flags & SymbolFlags.Value) {
7873+
if (s.flags & SymbolFlags.Value && exportedMember.flags & SymbolFlags.Value) {
78747874
// If the member has an additional value-like declaration, union the types from the two declarations,
78757875
// but issue an error if they occurred in two different files. The purpose is to support a JS file with
78767876
// a pattern like:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== /x.js ===
2+
module.exports.x = 1;
3+
>module.exports.x : Symbol(x, Decl(x.js, 0, 0), Decl(y.d.ts, 0, 0))
4+
>module.exports : Symbol(x, Decl(x.js, 0, 0), Decl(y.d.ts, 0, 0))
5+
>module : Symbol(module, Decl(x.js, 0, 0))
6+
>exports : Symbol("/x", Decl(x.js, 0, 0))
7+
>x : Symbol(x, Decl(x.js, 0, 0), Decl(y.d.ts, 0, 0))
8+
9+
module.exports = require("./y.js");
10+
>module.exports : Symbol("/x", Decl(x.js, 0, 0))
11+
>module : Symbol(export=, Decl(x.js, 0, 21))
12+
>exports : Symbol(export=, Decl(x.js, 0, 21))
13+
>require : Symbol(require)
14+
>"./y.js" : Symbol("/y", Decl(y.d.ts, 0, 0))
15+
16+
=== /y.d.ts ===
17+
export declare type x = 1;
18+
>x : Symbol(x, Decl(x.js, 0, 0), Decl(y.d.ts, 0, 0))
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== /x.js ===
2+
module.exports.x = 1;
3+
>module.exports.x = 1 : 1
4+
>module.exports.x : number
5+
>module.exports : typeof import("/y")
6+
>module : { "\"/x\"": typeof import("/y"); }
7+
>exports : typeof import("/y")
8+
>x : number
9+
>1 : 1
10+
11+
module.exports = require("./y.js");
12+
>module.exports = require("./y.js") : typeof import("/y")
13+
>module.exports : typeof import("/y")
14+
>module : { "\"/x\"": typeof import("/y"); }
15+
>exports : typeof import("/y")
16+
>require("./y.js") : typeof import("/y")
17+
>require : any
18+
>"./y.js" : "./y.js"
19+
20+
=== /y.d.ts ===
21+
export declare type x = 1;
22+
>x : 1
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
5+
// @Filename: /x.js
6+
module.exports.x = 1;
7+
module.exports = require("./y.js");
8+
9+
// @Filename: /y.d.ts
10+
export declare type x = 1;

0 commit comments

Comments
 (0)