Merge pull request #12594 from Microsoft/indexTypeNotFound

Handle parameter type error for index signature in declaration emit
This commit is contained in:
Sheetal Nandi
2016-11-30 16:43:35 -08:00
committed by GitHub
5 changed files with 45 additions and 0 deletions

View File

@@ -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)) {

View File

@@ -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",

View File

@@ -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'.
}

View File

@@ -0,0 +1,9 @@
//// [declarationEmitIndexTypeNotFound.ts]
export interface Test {
[index: TypeNotFound]: any;
}
//// [declarationEmitIndexTypeNotFound.js]
"use strict";

View File

@@ -0,0 +1,5 @@
// @declaration: true
export interface Test {
[index: TypeNotFound]: any;
}