From de465ad9312ac06be91bd96d35b16abd1c8d242b Mon Sep 17 00:00:00 2001 From: jbondc Date: Thu, 9 Apr 2015 07:48:40 -0400 Subject: [PATCH] Add more tests --- .../indexSignatureTypeCheck.errors.txt | 68 +++++++++++-------- .../reference/indexSignatureTypeCheck.js | 63 +++++++++++------ .../cases/compiler/indexSignatureTypeCheck.ts | 6 ++ 3 files changed, 86 insertions(+), 51 deletions(-) diff --git a/tests/baselines/reference/indexSignatureTypeCheck.errors.txt b/tests/baselines/reference/indexSignatureTypeCheck.errors.txt index 20890f3e13156..1931b5bd7dded 100644 --- a/tests/baselines/reference/indexSignatureTypeCheck.errors.txt +++ b/tests/baselines/reference/indexSignatureTypeCheck.errors.txt @@ -1,21 +1,21 @@ -tests/cases/compiler/indexSignatureTypeCheck.ts(35,1): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol, or 'any'. -tests/cases/compiler/indexSignatureTypeCheck.ts(38,8): error TS1019: An index signature parameter cannot have a question mark. -tests/cases/compiler/indexSignatureTypeCheck.ts(39,6): error TS1017: An index signature cannot have a rest parameter. +tests/cases/compiler/indexSignatureTypeCheck.ts(34,1): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol, or 'any'. +tests/cases/compiler/indexSignatureTypeCheck.ts(37,8): error TS1019: An index signature parameter cannot have a question mark. +tests/cases/compiler/indexSignatureTypeCheck.ts(38,6): error TS1017: An index signature cannot have a rest parameter. +tests/cases/compiler/indexSignatureTypeCheck.ts(39,6): error TS1096: An index signature must have exactly one parameter. tests/cases/compiler/indexSignatureTypeCheck.ts(40,6): error TS1096: An index signature must have exactly one parameter. -tests/cases/compiler/indexSignatureTypeCheck.ts(41,6): error TS1096: An index signature must have exactly one parameter. -tests/cases/compiler/indexSignatureTypeCheck.ts(51,2): error TS2375: Duplicate number index signature. -tests/cases/compiler/indexSignatureTypeCheck.ts(56,2): error TS2375: Duplicate number index signature. -tests/cases/compiler/indexSignatureTypeCheck.ts(64,1): error TS2322: Type '{ [x: number]: string; }' is not assignable to type '{ [x: string]: string; }'. +tests/cases/compiler/indexSignatureTypeCheck.ts(50,5): error TS2375: Duplicate number index signature. +tests/cases/compiler/indexSignatureTypeCheck.ts(55,5): error TS2375: Duplicate number index signature. +tests/cases/compiler/indexSignatureTypeCheck.ts(65,1): error TS2322: Type '{ [x: number]: string; }' is not assignable to type '{ [x: string]: string; }'. Index signature is missing in type '{ [x: number]: string; }'. -tests/cases/compiler/indexSignatureTypeCheck.ts(65,1): error TS2322: Type '{ [x: number]: number; }' is not assignable to type '{ [x: string]: string; }'. +tests/cases/compiler/indexSignatureTypeCheck.ts(66,1): error TS2322: Type '{ [x: number]: number; }' is not assignable to type '{ [x: string]: string; }'. Index signature is missing in type '{ [x: number]: number; }'. -tests/cases/compiler/indexSignatureTypeCheck.ts(69,1): error TS2322: Type '{ [x: number]: number; }' is not assignable to type '{ [x: number]: string; }'. +tests/cases/compiler/indexSignatureTypeCheck.ts(70,1): error TS2322: Type '{ [x: number]: number; }' is not assignable to type '{ [x: number]: string; }'. Index signatures are incompatible. Type 'number' is not assignable to type 'string'. -tests/cases/compiler/indexSignatureTypeCheck.ts(71,1): error TS2322: Type '{ [x: string]: string; }' is not assignable to type '{ [x: number]: number; }'. +tests/cases/compiler/indexSignatureTypeCheck.ts(72,1): error TS2322: Type '{ [x: string]: string; }' is not assignable to type '{ [x: number]: number; }'. Index signatures are incompatible. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/indexSignatureTypeCheck.ts(72,1): error TS2322: Type '{ [x: number]: string; }' is not assignable to type '{ [x: number]: number; }'. +tests/cases/compiler/indexSignatureTypeCheck.ts(73,1): error TS2322: Type '{ [x: number]: string; }' is not assignable to type '{ [x: number]: number; }'. Index signatures are incompatible. Type 'string' is not assignable to type 'number'. @@ -29,31 +29,30 @@ tests/cases/compiler/indexSignatureTypeCheck.ts(72,1): error TS2322: Type '{ [x: var index: any = "hello"; ps[index] = 12; - enum Val { + enum Values { a = 1, b = 2 } - type Val2 = Val; - type Val3 = number; + type Values2 = Values; + type Values3 = number; - interface IEnum { - [index: Val]: Val; + interface EnumMap { + [index: Values]: Values; } - - interface IEnum2 { - [index: Val2]: Val2; + interface EnumMap2 { + [index: Values2]: Values2; } - interface IEnum3 { - [index: Val3]: Val3; + interface NumberMap { + [index: Values3]: Values3; } - var pe: IEnum = null; + var pe: Values = null; pe[1] = null pe[3] = null - pe[Val.b] = 5 + pe[Values.b] = 5 pe[true] = null ~~~~~~~~ @@ -80,21 +79,23 @@ tests/cases/compiler/indexSignatureTypeCheck.ts(72,1): error TS2322: Type '{ [x: interface DuplicateAccess { - [index: Val]: Val; - [index: Val2]: Val2; - ~~~~~~~~~~~~~~~~~~~~ + [index: Values]: Values; + [index: Values2]: Values2; + ~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2375: Duplicate number index signature. } interface DuplicateAccess2 { - [index: number]: Val; - [index: Val3]: Val3; - ~~~~~~~~~~~~~~~~~~~~ + [index: number]: Values; + [index: Values3]: Values3; + ~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2375: Duplicate number index signature. } var x: { [x: string]: string } + var xn: {[x: string]: number } var y: { [x: number]: string } + var yn: { [x: number]: number } var z: { [x: E]: number } x = x; @@ -126,5 +127,14 @@ tests/cases/compiler/indexSignatureTypeCheck.ts(72,1): error TS2322: Type '{ [x: !!! error TS2322: Index signatures are incompatible. !!! error TS2322: Type 'string' is not assignable to type 'number'. z = z; + z = yn; + z = xn; + + // TODO: Should fail + yn = z; + type foo = string + var s: { [x: foo]: string } + x = s + s = x \ No newline at end of file diff --git a/tests/baselines/reference/indexSignatureTypeCheck.js b/tests/baselines/reference/indexSignatureTypeCheck.js index b1c8d075919a6..f373336dba7aa 100644 --- a/tests/baselines/reference/indexSignatureTypeCheck.js +++ b/tests/baselines/reference/indexSignatureTypeCheck.js @@ -7,31 +7,30 @@ var ps: IPropertySet = null; var index: any = "hello"; ps[index] = 12; -enum Val { +enum Values { a = 1, b = 2 } -type Val2 = Val; -type Val3 = number; +type Values2 = Values; +type Values3 = number; -interface IEnum { - [index: Val]: Val; +interface EnumMap { + [index: Values]: Values; } - -interface IEnum2 { - [index: Val2]: Val2; +interface EnumMap2 { + [index: Values2]: Values2; } -interface IEnum3 { - [index: Val3]: Val3; +interface NumberMap { + [index: Values3]: Values3; } -var pe: IEnum = null; +var pe: Values = null; pe[1] = null pe[3] = null -pe[Val.b] = 5 +pe[Values.b] = 5 pe[true] = null @@ -48,17 +47,19 @@ enum E { interface DuplicateAccess { - [index: Val]: Val; - [index: Val2]: Val2; + [index: Values]: Values; + [index: Values2]: Values2; } interface DuplicateAccess2 { - [index: number]: Val; - [index: Val3]: Val3; + [index: number]: Values; + [index: Values3]: Values3; } var x: { [x: string]: string } +var xn: {[x: string]: number } var y: { [x: number]: string } +var yn: { [x: number]: number } var z: { [x: E]: number } x = x; @@ -72,22 +73,31 @@ y = z; z = x; z = y; z = z; +z = yn; +z = xn; + +// TODO: Should fail +yn = z; +type foo = string +var s: { [x: foo]: string } +x = s +s = x //// [indexSignatureTypeCheck.js] var ps = null; var index = "hello"; ps[index] = 12; -var Val; -(function (Val) { - Val[Val["a"] = 1] = "a"; - Val[Val["b"] = 2] = "b"; -})(Val || (Val = {})); +var Values; +(function (Values) { + Values[Values["a"] = 1] = "a"; + Values[Values["b"] = 2] = "b"; +})(Values || (Values = {})); var pe = null; pe[1] = null; pe[3] = null; -pe[Val.b] = 5; +pe[Values.b] = 5; pe[true] = null; var E; (function (E) { @@ -96,7 +106,9 @@ var E; E[E["C"] = 2] = "C"; })(E || (E = {})); var x; +var xn; var y; +var yn; var z; x = x; x = y; @@ -107,3 +119,10 @@ y = z; z = x; z = y; z = z; +z = yn; +z = xn; +// TODO: Should fail +yn = z; +var s; +x = s; +s = x; diff --git a/tests/cases/compiler/indexSignatureTypeCheck.ts b/tests/cases/compiler/indexSignatureTypeCheck.ts index 6ed2dc51e6001..57f479b728e9d 100644 --- a/tests/cases/compiler/indexSignatureTypeCheck.ts +++ b/tests/cases/compiler/indexSignatureTypeCheck.ts @@ -56,7 +56,9 @@ interface DuplicateAccess2 { } var x: { [x: string]: string } +var xn: {[x: string]: number } var y: { [x: number]: string } +var yn: { [x: number]: number } var z: { [x: E]: number } x = x; @@ -70,7 +72,11 @@ y = z; z = x; z = y; z = z; +z = yn; +z = xn; +// TODO: Should fail +yn = z; type foo = string var s: { [x: foo]: string }