From 0d39fd95d2b8ef2753dce80f27edc83f4f64f008 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 30 Jul 2015 10:01:34 -0700 Subject: [PATCH] Adding numeric index signature to test --- .../reference/assignmentCompat1.errors.txt | 20 +++++++++++++------ .../baselines/reference/assignmentCompat1.js | 20 ++++++++++++------- tests/cases/compiler/assignmentCompat1.ts | 12 ++++++----- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/tests/baselines/reference/assignmentCompat1.errors.txt b/tests/baselines/reference/assignmentCompat1.errors.txt index 8e704400dbd..edb8d28eecc 100644 --- a/tests/baselines/reference/assignmentCompat1.errors.txt +++ b/tests/baselines/reference/assignmentCompat1.errors.txt @@ -1,13 +1,21 @@ tests/cases/compiler/assignmentCompat1.ts(4,1): error TS2322: Type '{ [index: string]: any; }' is not assignable to type '{ one: number; }'. Property 'one' is missing in type '{ [index: string]: any; }'. +tests/cases/compiler/assignmentCompat1.ts(6,1): error TS2322: Type '{ [index: number]: any; }' is not assignable to type '{ one: number; }'. + Property 'one' is missing in type '{ [index: number]: any; }'. -==== tests/cases/compiler/assignmentCompat1.ts (1 errors) ==== - var x = {one: 1}; - var y: {[index:string]: any}; - - x = y; +==== tests/cases/compiler/assignmentCompat1.ts (2 errors) ==== + var x = { one: 1 }; + var y: { [index: string]: any }; + var z: { [index: number]: any }; + x = y; // Error ~ !!! error TS2322: Type '{ [index: string]: any; }' is not assignable to type '{ one: number; }'. !!! error TS2322: Property 'one' is missing in type '{ [index: string]: any; }'. - y = x; \ No newline at end of file + y = x; // Ok because index signature type is any + x = z; // Error + ~ +!!! error TS2322: Type '{ [index: number]: any; }' is not assignable to type '{ one: number; }'. +!!! error TS2322: Property 'one' is missing in type '{ [index: number]: any; }'. + z = x; // Ok because index signature type is any + \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompat1.js b/tests/baselines/reference/assignmentCompat1.js index 09546b7165e..740a44cced4 100644 --- a/tests/baselines/reference/assignmentCompat1.js +++ b/tests/baselines/reference/assignmentCompat1.js @@ -1,12 +1,18 @@ //// [assignmentCompat1.ts] -var x = {one: 1}; -var y: {[index:string]: any}; - -x = y; -y = x; +var x = { one: 1 }; +var y: { [index: string]: any }; +var z: { [index: number]: any }; +x = y; // Error +y = x; // Ok because index signature type is any +x = z; // Error +z = x; // Ok because index signature type is any + //// [assignmentCompat1.js] var x = { one: 1 }; var y; -x = y; -y = x; +var z; +x = y; // Error +y = x; // Ok because index signature type is any +x = z; // Error +z = x; // Ok because index signature type is any diff --git a/tests/cases/compiler/assignmentCompat1.ts b/tests/cases/compiler/assignmentCompat1.ts index 552cdb7de0e..b37a11b20d9 100644 --- a/tests/cases/compiler/assignmentCompat1.ts +++ b/tests/cases/compiler/assignmentCompat1.ts @@ -1,5 +1,7 @@ -var x = {one: 1}; -var y: {[index:string]: any}; - -x = y; -y = x; \ No newline at end of file +var x = { one: 1 }; +var y: { [index: string]: any }; +var z: { [index: number]: any }; +x = y; // Error +y = x; // Ok because index signature type is any +x = z; // Error +z = x; // Ok because index signature type is any