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:
Nathan Shively-Sanders 2015-10-15 11:04:36 -07:00
parent 8eacd41ab0
commit 5cd0ca19af
3 changed files with 14 additions and 5 deletions

View File

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

View File

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

View File

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