diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4bdfa4b7250f2..4405a31db28f7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19180,6 +19180,8 @@ namespace ts { : DeclarationSpaces.ExportNamespace; case SyntaxKind.ClassDeclaration: case SyntaxKind.EnumDeclaration: + // A NamespaceImport declares an Alias, which is allowed to merge with other values within the module + case SyntaxKind.NamespaceImport: return DeclarationSpaces.ExportType | DeclarationSpaces.ExportValue; case SyntaxKind.ImportEqualsDeclaration: let result = DeclarationSpaces.None; diff --git a/tests/baselines/reference/noCrashOnImportShadowing.errors.txt b/tests/baselines/reference/noCrashOnImportShadowing.errors.txt new file mode 100644 index 0000000000000..c1d1dbcdef1a1 --- /dev/null +++ b/tests/baselines/reference/noCrashOnImportShadowing.errors.txt @@ -0,0 +1,33 @@ +tests/cases/compiler/index.ts(4,1): error TS2693: 'B' only refers to a type, but is being used as a value here. +tests/cases/compiler/index.ts(9,10): error TS2304: Cannot find name 'OriginalB'. + + +==== tests/cases/compiler/b.ts (0 errors) ==== + export const zzz = 123; + +==== tests/cases/compiler/a.ts (0 errors) ==== + import * as B from "./b"; + + interface B { + x: string; + } + + const x: B = { x: "" }; + B.zzz; + + export { B }; + +==== tests/cases/compiler/index.ts (2 errors) ==== + import { B } from "./a"; + + const x: B = { x: "" }; + B.zzz; + ~ +!!! error TS2693: 'B' only refers to a type, but is being used as a value here. + + import * as OriginalB from "./b"; + OriginalB.zzz; + + const y: OriginalB = x; + ~~~~~~~~~ +!!! error TS2304: Cannot find name 'OriginalB'. \ No newline at end of file diff --git a/tests/baselines/reference/noCrashOnImportShadowing.js b/tests/baselines/reference/noCrashOnImportShadowing.js new file mode 100644 index 0000000000000..7ca2116954d6f --- /dev/null +++ b/tests/baselines/reference/noCrashOnImportShadowing.js @@ -0,0 +1,46 @@ +//// [tests/cases/compiler/noCrashOnImportShadowing.ts] //// + +//// [b.ts] +export const zzz = 123; + +//// [a.ts] +import * as B from "./b"; + +interface B { + x: string; +} + +const x: B = { x: "" }; +B.zzz; + +export { B }; + +//// [index.ts] +import { B } from "./a"; + +const x: B = { x: "" }; +B.zzz; + +import * as OriginalB from "./b"; +OriginalB.zzz; + +const y: OriginalB = x; + +//// [b.js] +"use strict"; +exports.__esModule = true; +exports.zzz = 123; +//// [a.js] +"use strict"; +exports.__esModule = true; +var B = require("./b"); +var x = { x: "" }; +B.zzz; +//// [index.js] +"use strict"; +exports.__esModule = true; +var x = { x: "" }; +B.zzz; +var OriginalB = require("./b"); +OriginalB.zzz; +var y = x; diff --git a/tests/cases/compiler/noCrashOnImportShadowing.ts b/tests/cases/compiler/noCrashOnImportShadowing.ts new file mode 100644 index 0000000000000..69e8b6a0f8c01 --- /dev/null +++ b/tests/cases/compiler/noCrashOnImportShadowing.ts @@ -0,0 +1,25 @@ +// @filename: b.ts +export const zzz = 123; + +// @filename: a.ts +import * as B from "./b"; + +interface B { + x: string; +} + +const x: B = { x: "" }; +B.zzz; + +export { B }; + +// @filename: index.ts +import { B } from "./a"; + +const x: B = { x: "" }; +B.zzz; + +import * as OriginalB from "./b"; +OriginalB.zzz; + +const y: OriginalB = x; \ No newline at end of file