From adf9b26f50763ac9989d3a61df56bb74fc9007b1 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 30 Nov 2016 16:28:26 -0800 Subject: [PATCH] Handle parameter type error for index signature in declaration emit Fixes #12572 --- src/compiler/declarationEmitter.ts | 6 ++++++ src/compiler/diagnosticMessages.json | 8 ++++++++ .../declarationEmitIndexTypeNotFound.errors.txt | 17 +++++++++++++++++ .../declarationEmitIndexTypeNotFound.js | 9 +++++++++ .../declarationEmitIndexTypeNotFound.ts | 5 +++++ 5 files changed, 45 insertions(+) create mode 100644 tests/baselines/reference/declarationEmitIndexTypeNotFound.errors.txt create mode 100644 tests/baselines/reference/declarationEmitIndexTypeNotFound.js create mode 100644 tests/cases/compiler/declarationEmitIndexTypeNotFound.ts diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index fd2740f20c2e6..38e0db0ba6b74 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -1625,6 +1625,12 @@ namespace ts { Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; + case SyntaxKind.IndexSignature: + // Interfaces cannot have parameter types that cannot be named + return symbolAccessibilityResult.errorModuleName ? + Diagnostics.Parameter_0_of_index_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_index_signature_from_exported_interface_has_or_is_using_private_name_1; + case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: if (hasModifier(node.parent, ModifierFlags.Static)) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 007986e23bee0..5f49c54a2af22 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2300,6 +2300,14 @@ "category": "Message", "code": 4090 }, + "Parameter '{0}' of index signature from exported interface has or is using name '{1}' from private module '{2}'.": { + "category": "Error", + "code": 4091 + }, + "Parameter '{0}' of index signature from exported interface has or is using private name '{1}'.": { + "category": "Error", + "code": 4092 + }, "The current host does not support the '{0}' option.": { "category": "Error", diff --git a/tests/baselines/reference/declarationEmitIndexTypeNotFound.errors.txt b/tests/baselines/reference/declarationEmitIndexTypeNotFound.errors.txt new file mode 100644 index 0000000000000..ffbfd25fa949f --- /dev/null +++ b/tests/baselines/reference/declarationEmitIndexTypeNotFound.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(3,6): error TS1023: An index signature parameter type must be 'string' or 'number'. +tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(3,13): error TS2304: Cannot find name 'TypeNotFound'. +tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(3,13): error TS4092: Parameter 'index' of index signature from exported interface has or is using private name 'TypeNotFound'. + + +==== tests/cases/compiler/declarationEmitIndexTypeNotFound.ts (3 errors) ==== + + export interface Test { + [index: TypeNotFound]: any; + ~~~~~ +!!! error TS1023: An index signature parameter type must be 'string' or 'number'. + ~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'TypeNotFound'. + ~~~~~~~~~~~~ +!!! error TS4092: Parameter 'index' of index signature from exported interface has or is using private name 'TypeNotFound'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitIndexTypeNotFound.js b/tests/baselines/reference/declarationEmitIndexTypeNotFound.js new file mode 100644 index 0000000000000..22100e5cb7229 --- /dev/null +++ b/tests/baselines/reference/declarationEmitIndexTypeNotFound.js @@ -0,0 +1,9 @@ +//// [declarationEmitIndexTypeNotFound.ts] + +export interface Test { + [index: TypeNotFound]: any; +} + + +//// [declarationEmitIndexTypeNotFound.js] +"use strict"; diff --git a/tests/cases/compiler/declarationEmitIndexTypeNotFound.ts b/tests/cases/compiler/declarationEmitIndexTypeNotFound.ts new file mode 100644 index 0000000000000..de3316cd56f9e --- /dev/null +++ b/tests/cases/compiler/declarationEmitIndexTypeNotFound.ts @@ -0,0 +1,5 @@ +// @declaration: true + +export interface Test { + [index: TypeNotFound]: any; +}