Skip to content

Commit 6162001

Browse files
fix #33427 (#33486)
fix #33427
2 parents 114329a + 6a781f5 commit 6162001

27 files changed

+61
-61
lines changed

src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -35008,12 +35008,12 @@ namespace ts {
3500835008
typeToString(node.type ? getTypeFromTypeNode(node.type) : anyType));
3500935009
}
3501035010

35011-
if (type.flags & TypeFlags.Union && allTypesAssignableToKind(type, TypeFlags.StringLiteral, /*strict*/ true)) {
35011+
if (type.flags & TypeFlags.Union && allTypesAssignableToKind(type, TypeFlags.StringOrNumberLiteral, /*strict*/ true)) {
3501235012
return grammarErrorOnNode(parameter.name,
3501335013
Diagnostics.An_index_signature_parameter_type_cannot_be_a_union_type_Consider_using_a_mapped_object_type_instead);
3501435014
}
3501535015

35016-
return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_must_be_string_or_number);
35016+
return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_must_be_either_string_or_number);
3501735017
}
3501835018
if (!node.type) {
3501935019
return grammarErrorOnNode(node, Diagnostics.An_index_signature_must_have_a_type_annotation);

src/compiler/diagnosticMessages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"category": "Error",
7272
"code": 1022
7373
},
74-
"An index signature parameter type must be 'string' or 'number'.": {
74+
"An index signature parameter type must be either 'string' or 'number'.": {
7575
"category": "Error",
7676
"code": 1023
7777
},

tests/baselines/reference/arraySigChecking.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/arraySigChecking.ts(11,17): error TS1023: An index signature parameter type must be 'string' or 'number'.
1+
tests/cases/compiler/arraySigChecking.ts(11,17): error TS1023: An index signature parameter type must be either 'string' or 'number'.
22
tests/cases/compiler/arraySigChecking.ts(18,27): error TS2322: Type 'void' is not assignable to type 'string'.
33
tests/cases/compiler/arraySigChecking.ts(22,13): error TS2322: Type 'number' is not assignable to type 'number[]'.
44
tests/cases/compiler/arraySigChecking.ts(22,16): error TS2322: Type 'number' is not assignable to type 'number[]'.
@@ -17,7 +17,7 @@ tests/cases/compiler/arraySigChecking.ts(22,16): error TS2322: Type 'number' is
1717

1818
var foo: { [index: any]; }; // expect an error here
1919
~~~~~
20-
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
20+
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'.
2121
}
2222

2323
interface myInt {

tests/baselines/reference/bigintIndex.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/a.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
1+
tests/cases/compiler/a.ts(2,6): error TS1023: An index signature parameter type must be either 'string' or 'number'.
22
tests/cases/compiler/a.ts(8,11): error TS2538: Type '1n' cannot be used as an index type.
33
tests/cases/compiler/a.ts(14,1): error TS2322: Type '123n' is not assignable to type 'string | number | symbol'.
44
tests/cases/compiler/a.ts(19,12): error TS2538: Type 'bigint' cannot be used as an index type.
@@ -13,7 +13,7 @@ tests/cases/compiler/b.ts(4,12): error TS2464: A computed property name must be
1313
interface BigIntIndex<E> {
1414
[index: bigint]: E; // should error
1515
~~~~~
16-
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
16+
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'.
1717
}
1818

1919
const arr: number[] = [1, 2, 3];

tests/baselines/reference/declarationEmitIndexTypeNotFound.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
1+
tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(2,6): error TS1023: An index signature parameter type must be either 'string' or 'number'.
22
tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(2,13): error TS2304: Cannot find name 'TypeNotFound'.
33
tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(2,13): error TS4092: Parameter 'index' of index signature from exported interface has or is using private name 'TypeNotFound'.
44

@@ -7,7 +7,7 @@ tests/cases/compiler/declarationEmitIndexTypeNotFound.ts(2,13): error TS4092: Pa
77
export interface Test {
88
[index: TypeNotFound]: any;
99
~~~~~
10-
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
10+
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'.
1111
~~~~~~~~~~~~
1212
!!! error TS2304: Cannot find name 'TypeNotFound'.
1313
~~~~~~~~~~~~
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/compiler/genericIndexTypeHasSensibleErrorMessage.ts(1,33): error TS1023: An index signature parameter type must be 'string' or 'number'.
1+
tests/cases/compiler/genericIndexTypeHasSensibleErrorMessage.ts(1,33): error TS1023: An index signature parameter type must be either 'string' or 'number'.
22

33

44
==== tests/cases/compiler/genericIndexTypeHasSensibleErrorMessage.ts (1 errors) ====
55
type Wat<T extends string> = { [x: T]: string };
66
~
7-
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
7+
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'.

tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.d.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc
22
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(10,21): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
33
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(11,22): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
44
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(11,26): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
5-
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(12,19): error TS1023: An index signature parameter type must be 'string' or 'number'.
5+
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(12,19): error TS1023: An index signature parameter type must be either 'string' or 'number'.
66
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(12,22): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
77
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(12,26): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
88
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.d.ts(14,23): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
@@ -36,7 +36,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc
3636
!!! error TS2314: Generic type 'C<T>' requires 1 type argument(s).
3737
declare var d: { [x: C]: C };
3838
~
39-
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
39+
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'.
4040
~
4141
!!! error TS2314: Generic type 'C<T>' requires 1 type argument(s).
4242
~

tests/baselines/reference/genericTypeReferenceWithoutTypeArgument.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc
22
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(10,13): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
33
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(11,14): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
44
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(11,18): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
5-
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(12,11): error TS1023: An index signature parameter type must be 'string' or 'number'.
5+
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(12,11): error TS1023: An index signature parameter type must be either 'string' or 'number'.
66
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(12,14): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
77
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(12,18): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
88
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument.ts(14,13): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
@@ -46,7 +46,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc
4646
!!! error TS2314: Generic type 'C<T>' requires 1 type argument(s).
4747
var d: { [x: C]: C };
4848
~
49-
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
49+
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'.
5050
~
5151
!!! error TS2314: Generic type 'C<T>' requires 1 type argument(s).
5252
~

tests/baselines/reference/genericTypeReferenceWithoutTypeArgument2.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc
22
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(10,13): error TS2314: Generic type 'I<T>' requires 1 type argument(s).
33
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(11,14): error TS2314: Generic type 'I<T>' requires 1 type argument(s).
44
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(11,18): error TS2314: Generic type 'I<T>' requires 1 type argument(s).
5-
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(12,11): error TS1023: An index signature parameter type must be 'string' or 'number'.
5+
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(12,11): error TS1023: An index signature parameter type must be either 'string' or 'number'.
66
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(12,14): error TS2314: Generic type 'I<T>' requires 1 type argument(s).
77
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(12,18): error TS2314: Generic type 'I<T>' requires 1 type argument(s).
88
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument2.ts(14,13): error TS2314: Generic type 'I<T>' requires 1 type argument(s).
@@ -46,7 +46,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc
4646
!!! error TS2314: Generic type 'I<T>' requires 1 type argument(s).
4747
var d: { [x: I]: I };
4848
~
49-
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
49+
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'.
5050
~
5151
!!! error TS2314: Generic type 'I<T>' requires 1 type argument(s).
5252
~

tests/baselines/reference/genericTypeReferenceWithoutTypeArgument3.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc
22
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(10,21): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
33
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(11,22): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
44
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(11,26): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
5-
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(12,19): error TS1023: An index signature parameter type must be 'string' or 'number'.
5+
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(12,19): error TS1023: An index signature parameter type must be either 'string' or 'number'.
66
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(12,22): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
77
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(12,26): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
88
tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenceWithoutTypeArgument3.ts(14,23): error TS2314: Generic type 'C<T>' requires 1 type argument(s).
@@ -36,7 +36,7 @@ tests/cases/conformance/types/specifyingTypes/typeReferences/genericTypeReferenc
3636
!!! error TS2314: Generic type 'C<T>' requires 1 type argument(s).
3737
declare var d: { [x: C]: C };
3838
~
39-
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
39+
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'.
4040
~
4141
!!! error TS2314: Generic type 'C<T>' requires 1 type argument(s).
4242
~

tests/baselines/reference/indexTypeCheck.errors.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ tests/cases/compiler/indexTypeCheck.ts(17,2): error TS2413: Numeric index type '
44
tests/cases/compiler/indexTypeCheck.ts(22,2): error TS2413: Numeric index type 'Orange' is not assignable to string index type 'Yellow'.
55
tests/cases/compiler/indexTypeCheck.ts(27,2): error TS2413: Numeric index type 'number' is not assignable to string index type 'string'.
66
tests/cases/compiler/indexTypeCheck.ts(32,3): error TS1096: An index signature must have exactly one parameter.
7-
tests/cases/compiler/indexTypeCheck.ts(36,3): error TS1023: An index signature parameter type must be 'string' or 'number'.
7+
tests/cases/compiler/indexTypeCheck.ts(36,3): error TS1023: An index signature parameter type must be either 'string' or 'number'.
88
tests/cases/compiler/indexTypeCheck.ts(51,8): error TS2538: Type 'Blue' cannot be used as an index type.
99

1010

@@ -58,7 +58,7 @@ tests/cases/compiler/indexTypeCheck.ts(51,8): error TS2538: Type 'Blue' cannot b
5858
interface Magenta {
5959
[p:Purple]; // error
6060
~
61-
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
61+
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'.
6262
}
6363

6464
var yellow: Yellow;

tests/baselines/reference/indexerConstraints2.errors.txt

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ tests/cases/compiler/indexerConstraints2.ts(17,5): error TS2413: Numeric index t
33
tests/cases/compiler/indexerConstraints2.ts(26,5): error TS2413: Numeric index type 'A' is not assignable to string index type 'B'.
44
tests/cases/compiler/indexerConstraints2.ts(34,6): error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[n: number]: A' instead.
55
tests/cases/compiler/indexerConstraints2.ts(40,6): error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[s: string]: A' instead.
6-
tests/cases/compiler/indexerConstraints2.ts(46,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
6+
tests/cases/compiler/indexerConstraints2.ts(46,6): error TS1023: An index signature parameter type must be either 'string' or 'number'.
77
tests/cases/compiler/indexerConstraints2.ts(52,6): error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
8-
tests/cases/compiler/indexerConstraints2.ts(58,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
9-
tests/cases/compiler/indexerConstraints2.ts(64,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
10-
tests/cases/compiler/indexerConstraints2.ts(70,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
8+
tests/cases/compiler/indexerConstraints2.ts(58,6): error TS1023: An index signature parameter type must be either 'string' or 'number'.
9+
tests/cases/compiler/indexerConstraints2.ts(64,6): error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
10+
tests/cases/compiler/indexerConstraints2.ts(70,6): error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
1111
tests/cases/compiler/indexerConstraints2.ts(74,6): error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
1212
tests/cases/compiler/indexerConstraints2.ts(79,6): error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[key: string]: any' instead.
1313

@@ -70,7 +70,7 @@ tests/cases/compiler/indexerConstraints2.ts(79,6): error TS1336: An index signat
7070
interface N {
7171
[b: AliasedBoolean]: A;
7272
~
73-
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
73+
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'.
7474
}
7575

7676
type IndexableUnion = "foo" | "bar";
@@ -86,23 +86,23 @@ tests/cases/compiler/indexerConstraints2.ts(79,6): error TS1336: An index signat
8686
interface P {
8787
[u: NonIndexableUnion]: A;
8888
~
89-
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
89+
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'.
9090
}
9191

9292
type NonIndexableUnion2 = string | number;
9393

9494
interface Q {
9595
[u: NonIndexableUnion2]: A;
9696
~
97-
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
97+
!!! error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
9898
}
9999

100100
type NonIndexableUnion3 = "foo" | 42;
101101

102102
interface R {
103103
[u: NonIndexableUnion3]: A;
104104
~
105-
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
105+
!!! error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
106106
}
107107

108108
interface S {
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer1.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
1+
tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer1.ts(2,6): error TS1023: An index signature parameter type must be either 'string' or 'number'.
22

33

44
==== tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer1.ts (1 errors) ====
55
interface I {
66
[s: symbol]: string;
77
~
8-
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
8+
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'.
99
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer2.ts(2,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
1+
tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer2.ts(2,6): error TS1023: An index signature parameter type must be either 'string' or 'number'.
22

33

44
==== tests/cases/conformance/parser/ecmascript5/Symbols/parserES5SymbolIndexer2.ts (1 errors) ====
55
class C {
66
[s: symbol]: string;
77
~
8-
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
8+
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'.
99
}

0 commit comments

Comments
 (0)