Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jbondc committed Apr 9, 2015
1 parent 6225c77 commit de465ad
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 51 deletions.
68 changes: 39 additions & 29 deletions tests/baselines/reference/indexSignatureTypeCheck.errors.txt
Original file line number Diff line number Diff line change
@@ -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'.

Expand All @@ -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
~~~~~~~~
Expand All @@ -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;
Expand Down Expand Up @@ -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

63 changes: 41 additions & 22 deletions tests/baselines/reference/indexSignatureTypeCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
Expand All @@ -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;
6 changes: 6 additions & 0 deletions tests/cases/compiler/indexSignatureTypeCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 }
Expand Down

0 comments on commit de465ad

Please sign in to comment.