2014-09-12 22:35:07 +02:00
|
|
|
tests/cases/compiler/indexTypeCheck.ts(2,2): error TS1021: An index signature must have a type annotation.
|
|
|
|
tests/cases/compiler/indexTypeCheck.ts(3,2): error TS1021: An index signature must have a type annotation.
|
|
|
|
tests/cases/compiler/indexTypeCheck.ts(17,2): error TS2413: Numeric index type 'number' is not assignable to string index type 'string'.
|
|
|
|
tests/cases/compiler/indexTypeCheck.ts(22,2): error TS2413: Numeric index type 'Orange' is not assignable to string index type 'Yellow'.
|
|
|
|
tests/cases/compiler/indexTypeCheck.ts(27,2): error TS2413: Numeric index type 'number' is not assignable to string index type 'string'.
|
2014-12-17 00:56:56 +01:00
|
|
|
tests/cases/compiler/indexTypeCheck.ts(32,3): error TS1096: An index signature must have exactly one parameter.
|
2015-02-07 06:30:51 +01:00
|
|
|
tests/cases/compiler/indexTypeCheck.ts(36,3): error TS1023: An index signature parameter type must be 'string' or 'number'.
|
2015-02-06 03:11:17 +01:00
|
|
|
tests/cases/compiler/indexTypeCheck.ts(51,1): error TS2342: An index expression argument must be of type 'string', 'number', 'symbol, or 'any'.
|
2014-09-12 22:35:07 +02:00
|
|
|
|
|
|
|
|
2014-07-13 01:04:16 +02:00
|
|
|
==== tests/cases/compiler/indexTypeCheck.ts (8 errors) ====
|
|
|
|
interface Red {
|
|
|
|
[n:number]; // ok
|
2014-11-19 03:20:41 +01:00
|
|
|
~~~~~~~~~~~
|
2014-09-12 00:19:57 +02:00
|
|
|
!!! error TS1021: An index signature must have a type annotation.
|
2014-07-13 01:04:16 +02:00
|
|
|
[s:string]; // ok
|
2014-11-19 03:20:41 +01:00
|
|
|
~~~~~~~~~~~
|
2014-09-12 00:19:57 +02:00
|
|
|
!!! error TS1021: An index signature must have a type annotation.
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
interface Blue {
|
|
|
|
[n:number]: any; // ok
|
|
|
|
[s:string]: any; // ok
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Yellow {
|
|
|
|
[n:number]: Red; // ok
|
|
|
|
[s:string]: Red; // ok
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Orange {
|
|
|
|
[n:number]: number; // ok
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
2014-09-12 00:19:57 +02:00
|
|
|
!!! error TS2413: Numeric index type 'number' is not assignable to string index type 'string'.
|
2014-07-13 01:04:16 +02:00
|
|
|
[s:string]: string; // error
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Green {
|
|
|
|
[n:number]: Orange; // error
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
2014-09-12 00:19:57 +02:00
|
|
|
!!! error TS2413: Numeric index type 'Orange' is not assignable to string index type 'Yellow'.
|
2014-07-13 01:04:16 +02:00
|
|
|
[s:string]: Yellow; // ok
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Cyan {
|
|
|
|
[n:number]: number; // error
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
2014-09-12 00:19:57 +02:00
|
|
|
!!! error TS2413: Numeric index type 'number' is not assignable to string index type 'string'.
|
2014-07-13 01:04:16 +02:00
|
|
|
[s:string]: string; // ok
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Purple {
|
|
|
|
[n:number, s:string]; // error
|
|
|
|
~
|
2014-09-12 00:19:57 +02:00
|
|
|
!!! error TS1096: An index signature must have exactly one parameter.
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
interface Magenta {
|
|
|
|
[p:Purple]; // error
|
|
|
|
~
|
2015-02-07 06:30:51 +01:00
|
|
|
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
|
2014-07-13 01:04:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var yellow: Yellow;
|
|
|
|
var blue: Blue;
|
|
|
|
var s = "some string";
|
|
|
|
|
|
|
|
yellow[5]; // ok
|
|
|
|
yellow["hue"]; // ok
|
|
|
|
yellow[<any>{}]; // ok
|
|
|
|
|
|
|
|
s[0]; // error
|
|
|
|
s["s"]; // ok
|
|
|
|
s[<any>{}]; // ok
|
|
|
|
|
|
|
|
yellow[blue]; // error
|
|
|
|
~~~~~~~~~~~~
|
2015-02-06 03:11:17 +01:00
|
|
|
!!! error TS2342: An index expression argument must be of type 'string', 'number', 'symbol, or 'any'.
|
2014-07-13 01:04:16 +02:00
|
|
|
|
|
|
|
var x:number[];
|
|
|
|
x[0];
|
|
|
|
|
|
|
|
class Benchmark {
|
|
|
|
|
|
|
|
public results: { [x:string]: any; } = <{ [x:string]: any; }>{};
|
|
|
|
|
|
|
|
public addTimingFor(name: string, timing: number) {
|
|
|
|
this.results[name] = this.results[name];
|
|
|
|
}
|
|
|
|
}
|