From 5cd0ca19af72f1cdeebf16e3310bf746a567afce Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 15 Oct 2015 11:04:36 -0700 Subject: [PATCH] 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. --- tests/baselines/reference/assignmentCompat1.errors.txt | 10 ++++++++-- tests/baselines/reference/assignmentCompat1.js | 6 ++++-- tests/cases/compiler/assignmentCompat1.ts | 3 ++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/baselines/reference/assignmentCompat1.errors.txt b/tests/baselines/reference/assignmentCompat1.errors.txt index 93afdbe1bcb..7539af92887 100644 --- a/tests/baselines/reference/assignmentCompat1.errors.txt +++ b/tests/baselines/reference/assignmentCompat1.errors.txt @@ -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'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompat1.js b/tests/baselines/reference/assignmentCompat1.js index a873c24c567..7451d342fa1 100644 --- a/tests/baselines/reference/assignmentCompat1.js +++ b/tests/baselines/reference/assignmentCompat1.js @@ -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 diff --git a/tests/cases/compiler/assignmentCompat1.ts b/tests/cases/compiler/assignmentCompat1.ts index 54dc91adab0..e93da76d95e 100644 --- a/tests/cases/compiler/assignmentCompat1.ts +++ b/tests/cases/compiler/assignmentCompat1.ts @@ -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