Skip to content

Commit 5cd0ca1

Browse files
committed
Add test case, correct existing test case
Existing: String assignment to a numeric indexer should succeed, not fail. (The baseline was already correct but the inline comment was wrong.) New: Boolean assignment to a numeric indexer should fail.
1 parent 8eacd41 commit 5cd0ca1

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

tests/baselines/reference/assignmentCompat1.errors.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ tests/cases/compiler/assignmentCompat1.ts(6,1): error TS2322: Type '{ [index: nu
44
Property 'one' is missing in type '{ [index: number]: any; }'.
55
tests/cases/compiler/assignmentCompat1.ts(8,1): error TS2322: Type 'string' is not assignable to type '{ [index: string]: any; }'.
66
Index signature is missing in type 'String'.
7+
tests/cases/compiler/assignmentCompat1.ts(10,1): error TS2322: Type 'boolean' is not assignable to type '{ [index: number]: any; }'.
8+
Index signature is missing in type 'Boolean'.
79

810

9-
==== tests/cases/compiler/assignmentCompat1.ts (3 errors) ====
11+
==== tests/cases/compiler/assignmentCompat1.ts (4 errors) ====
1012
var x = { one: 1 };
1113
var y: { [index: string]: any };
1214
var z: { [index: number]: any };
@@ -24,6 +26,10 @@ tests/cases/compiler/assignmentCompat1.ts(8,1): error TS2322: Type 'string' is n
2426
~
2527
!!! error TS2322: Type 'string' is not assignable to type '{ [index: string]: any; }'.
2628
!!! error TS2322: Index signature is missing in type 'String'.
27-
z = "foo"; // Error
29+
z = "foo"; // OK, string has numeric indexer
30+
z = false; // Error
31+
~
32+
!!! error TS2322: Type 'boolean' is not assignable to type '{ [index: number]: any; }'.
33+
!!! error TS2322: Index signature is missing in type 'Boolean'.
2834

2935

tests/baselines/reference/assignmentCompat1.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ y = x; // Ok because index signature type is any
77
x = z; // Error
88
z = x; // Ok because index signature type is any
99
y = "foo"; // Error
10-
z = "foo"; // Error
10+
z = "foo"; // OK, string has numeric indexer
11+
z = false; // Error
1112

1213

1314

@@ -20,4 +21,5 @@ y = x; // Ok because index signature type is any
2021
x = z; // Error
2122
z = x; // Ok because index signature type is any
2223
y = "foo"; // Error
23-
z = "foo"; // Error
24+
z = "foo"; // OK, string has numeric indexer
25+
z = false; // Error

tests/cases/compiler/assignmentCompat1.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ y = x; // Ok because index signature type is any
66
x = z; // Error
77
z = x; // Ok because index signature type is any
88
y = "foo"; // Error
9-
z = "foo"; // Error
9+
z = "foo"; // OK, string has numeric indexer
10+
z = false; // Error
1011

0 commit comments

Comments
 (0)