diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d3ff399e9a5dd..2d19a147a29ba 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7870,7 +7870,7 @@ namespace ts { (resolvedSymbol || symbol).exports!.forEach((s, name) => { const exportedMember = members.get(name)!; if (exportedMember && exportedMember !== s) { - if (s.flags & SymbolFlags.Value) { + if (s.flags & SymbolFlags.Value && exportedMember.flags & SymbolFlags.Value) { // If the member has an additional value-like declaration, union the types from the two declarations, // but issue an error if they occurred in two different files. The purpose is to support a JS file with // a pattern like: diff --git a/tests/baselines/reference/jsExportMemberMergedWithModuleAugmentation3.symbols b/tests/baselines/reference/jsExportMemberMergedWithModuleAugmentation3.symbols new file mode 100644 index 0000000000000..c56d389851016 --- /dev/null +++ b/tests/baselines/reference/jsExportMemberMergedWithModuleAugmentation3.symbols @@ -0,0 +1,19 @@ +=== /x.js === +module.exports.x = 1; +>module.exports.x : Symbol(x, Decl(x.js, 0, 0), Decl(y.d.ts, 0, 0)) +>module.exports : Symbol(x, Decl(x.js, 0, 0), Decl(y.d.ts, 0, 0)) +>module : Symbol(module, Decl(x.js, 0, 0)) +>exports : Symbol("/x", Decl(x.js, 0, 0)) +>x : Symbol(x, Decl(x.js, 0, 0), Decl(y.d.ts, 0, 0)) + +module.exports = require("./y.js"); +>module.exports : Symbol("/x", Decl(x.js, 0, 0)) +>module : Symbol(export=, Decl(x.js, 0, 21)) +>exports : Symbol(export=, Decl(x.js, 0, 21)) +>require : Symbol(require) +>"./y.js" : Symbol("/y", Decl(y.d.ts, 0, 0)) + +=== /y.d.ts === +export declare type x = 1; +>x : Symbol(x, Decl(x.js, 0, 0), Decl(y.d.ts, 0, 0)) + diff --git a/tests/baselines/reference/jsExportMemberMergedWithModuleAugmentation3.types b/tests/baselines/reference/jsExportMemberMergedWithModuleAugmentation3.types new file mode 100644 index 0000000000000..6c66c601ffccb --- /dev/null +++ b/tests/baselines/reference/jsExportMemberMergedWithModuleAugmentation3.types @@ -0,0 +1,23 @@ +=== /x.js === +module.exports.x = 1; +>module.exports.x = 1 : 1 +>module.exports.x : number +>module.exports : typeof import("/y") +>module : { "\"/x\"": typeof import("/y"); } +>exports : typeof import("/y") +>x : number +>1 : 1 + +module.exports = require("./y.js"); +>module.exports = require("./y.js") : typeof import("/y") +>module.exports : typeof import("/y") +>module : { "\"/x\"": typeof import("/y"); } +>exports : typeof import("/y") +>require("./y.js") : typeof import("/y") +>require : any +>"./y.js" : "./y.js" + +=== /y.d.ts === +export declare type x = 1; +>x : 1 + diff --git a/tests/cases/compiler/jsExportMemberMergedWithModuleAugmentation3.ts b/tests/cases/compiler/jsExportMemberMergedWithModuleAugmentation3.ts new file mode 100644 index 0000000000000..526326610d88a --- /dev/null +++ b/tests/cases/compiler/jsExportMemberMergedWithModuleAugmentation3.ts @@ -0,0 +1,10 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true + +// @Filename: /x.js +module.exports.x = 1; +module.exports = require("./y.js"); + +// @Filename: /y.d.ts +export declare type x = 1;