From 39040f61540c2a2ec3cb9a9cc5c2920a3a0188fe Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 7 Dec 2016 13:13:21 -0800 Subject: [PATCH] Provide better error message --- src/compiler/checker.ts | 3 +++ src/compiler/diagnosticMessages.json | 4 ++++ .../reference/augmentExportEquals7.errors.txt | 12 +++--------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 903c8cfda1c..d2d4502c79d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -479,6 +479,9 @@ namespace ts { } recordMergedSymbol(target, source); } + else if (target.flags & SymbolFlags.NamespaceModule) { + error(source.valueDeclaration.name, Diagnostics.Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity, symbolToString(target)); + } else { const message = target.flags & SymbolFlags.BlockScopedVariable || source.flags & SymbolFlags.BlockScopedVariable ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 4d42c77e566..19b297fd4a9 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1807,6 +1807,10 @@ "category": "Error", "code": 2608 }, + "Cannot augment module '{0}' with value exports because it resolves to a non-module entity.": { + "category": "Error", + "code": 2649 + }, "Cannot emit namespaced JSX elements in React": { "category": "Error", "code": 2650 diff --git a/tests/baselines/reference/augmentExportEquals7.errors.txt b/tests/baselines/reference/augmentExportEquals7.errors.txt index 1cb9ddc041c..e13cf037023 100644 --- a/tests/baselines/reference/augmentExportEquals7.errors.txt +++ b/tests/baselines/reference/augmentExportEquals7.errors.txt @@ -1,22 +1,16 @@ -/node_modules/@types/lib-extender/index.d.ts(2,16): error TS2300: Duplicate identifier '"lib"'. -/node_modules/lib/index.d.ts(1,13): error TS2300: Duplicate identifier '"lib"'. -/node_modules/lib/index.d.ts(2,19): error TS2300: Duplicate identifier '"lib"'. +/node_modules/@types/lib-extender/index.d.ts(2,16): error TS2649: Cannot augment module 'lib' with value exports because it resolves to a non-module entity. -==== /node_modules/lib/index.d.ts (2 errors) ==== +==== /node_modules/lib/index.d.ts (0 errors) ==== declare var lib: () => void; - ~~~ -!!! error TS2300: Duplicate identifier '"lib"'. declare namespace lib {} - ~~~ -!!! error TS2300: Duplicate identifier '"lib"'. export = lib; ==== /node_modules/@types/lib-extender/index.d.ts (1 errors) ==== import * as lib from "lib"; declare module "lib" { ~~~~~ -!!! error TS2300: Duplicate identifier '"lib"'. +!!! error TS2649: Cannot augment module 'lib' with value exports because it resolves to a non-module entity. export function fn(): void; } \ No newline at end of file