Skip to content

Commit 09f158d

Browse files
authored
Merge pull request #12594 from Microsoft/indexTypeNotFound
Handle parameter type error for index signature in declaration emit
2 parents 7a42000 + adf9b26 commit 09f158d

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

src/compiler/declarationEmitter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,12 @@ namespace ts {
16251625
Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
16261626
Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
16271627

1628+
case SyntaxKind.IndexSignature:
1629+
// Interfaces cannot have parameter types that cannot be named
1630+
return symbolAccessibilityResult.errorModuleName ?
1631+
Diagnostics.Parameter_0_of_index_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
1632+
Diagnostics.Parameter_0_of_index_signature_from_exported_interface_has_or_is_using_private_name_1;
1633+
16281634
case SyntaxKind.MethodDeclaration:
16291635
case SyntaxKind.MethodSignature:
16301636
if (hasModifier(node.parent, ModifierFlags.Static)) {

src/compiler/diagnosticMessages.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,6 +2300,14 @@
23002300
"category": "Message",
23012301
"code": 4090
23022302
},
2303+
"Parameter '{0}' of index signature from exported interface has or is using name '{1}' from private module '{2}'.": {
2304+
"category": "Error",
2305+
"code": 4091
2306+
},
2307+
"Parameter '{0}' of index signature from exported interface has or is using private name '{1}'.": {
2308+
"category": "Error",
2309+
"code": 4092
2310+
},
23032311

23042312
"The current host does not support the '{0}' option.": {
23052313
"category": "Error",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(3,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
2+
tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(3,13): error TS2304: Cannot find name 'TypeNotFound'.
3+
tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(3,13): error TS4092: Parameter 'index' of index signature from exported interface has or is using private name 'TypeNotFound'.
4+
5+
6+
==== tests/cases/compiler/declarationEmitIndexTypeNotFound.ts (3 errors) ====
7+
8+
export interface Test {
9+
[index: TypeNotFound]: any;
10+
~~~~~
11+
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
12+
~~~~~~~~~~~~
13+
!!! error TS2304: Cannot find name 'TypeNotFound'.
14+
~~~~~~~~~~~~
15+
!!! error TS4092: Parameter 'index' of index signature from exported interface has or is using private name 'TypeNotFound'.
16+
}
17+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [declarationEmitIndexTypeNotFound.ts]
2+
3+
export interface Test {
4+
[index: TypeNotFound]: any;
5+
}
6+
7+
8+
//// [declarationEmitIndexTypeNotFound.js]
9+
"use strict";
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// @declaration: true
2+
3+
export interface Test {
4+
[index: TypeNotFound]: any;
5+
}

0 commit comments

Comments
 (0)