mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
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.
This commit is contained in:
parent
8eacd41ab0
commit
5cd0ca19af
@ -4,9 +4,11 @@ tests/cases/compiler/assignmentCompat1.ts(6,1): error TS2322: Type '{ [index: nu
|
||||
Property 'one' is missing in type '{ [index: number]: any; }'.
|
||||
tests/cases/compiler/assignmentCompat1.ts(8,1): error TS2322: Type 'string' is not assignable to type '{ [index: string]: any; }'.
|
||||
Index signature is missing in type 'String'.
|
||||
tests/cases/compiler/assignmentCompat1.ts(10,1): error TS2322: Type 'boolean' is not assignable to type '{ [index: number]: any; }'.
|
||||
Index signature is missing in type 'Boolean'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/assignmentCompat1.ts (3 errors) ====
|
||||
==== tests/cases/compiler/assignmentCompat1.ts (4 errors) ====
|
||||
var x = { one: 1 };
|
||||
var y: { [index: string]: any };
|
||||
var z: { [index: number]: any };
|
||||
@ -24,6 +26,10 @@ tests/cases/compiler/assignmentCompat1.ts(8,1): error TS2322: Type 'string' is n
|
||||
~
|
||||
!!! error TS2322: Type 'string' is not assignable to type '{ [index: string]: any; }'.
|
||||
!!! error TS2322: Index signature is missing in type 'String'.
|
||||
z = "foo"; // Error
|
||||
z = "foo"; // OK, string has numeric indexer
|
||||
z = false; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'boolean' is not assignable to type '{ [index: number]: any; }'.
|
||||
!!! error TS2322: Index signature is missing in type 'Boolean'.
|
||||
|
||||
|
||||
@ -7,7 +7,8 @@ y = x; // Ok because index signature type is any
|
||||
x = z; // Error
|
||||
z = x; // Ok because index signature type is any
|
||||
y = "foo"; // Error
|
||||
z = "foo"; // Error
|
||||
z = "foo"; // OK, string has numeric indexer
|
||||
z = false; // Error
|
||||
|
||||
|
||||
|
||||
@ -20,4 +21,5 @@ y = x; // Ok because index signature type is any
|
||||
x = z; // Error
|
||||
z = x; // Ok because index signature type is any
|
||||
y = "foo"; // Error
|
||||
z = "foo"; // Error
|
||||
z = "foo"; // OK, string has numeric indexer
|
||||
z = false; // Error
|
||||
|
||||
@ -6,5 +6,6 @@ y = x; // Ok because index signature type is any
|
||||
x = z; // Error
|
||||
z = x; // Ok because index signature type is any
|
||||
y = "foo"; // Error
|
||||
z = "foo"; // Error
|
||||
z = "foo"; // OK, string has numeric indexer
|
||||
z = false; // Error
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user