f1a2e41a8a
This was we don't get noisy baselines just because a different phase of the compiler reported the diagnostic. This helps with Yui's refactoring work to move grammar checks into the type checker.
90 lines
3.1 KiB
Plaintext
90 lines
3.1 KiB
Plaintext
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'.
|
|
tests/cases/compiler/indexTypeCheck.ts(32,3): error TS1096: An index signature must have exactly one parameter.
|
|
tests/cases/compiler/indexTypeCheck.ts(36,3): error TS1023: An index signature parameter type must be 'string' or 'number'.
|
|
tests/cases/compiler/indexTypeCheck.ts(51,1): error TS2342: An index expression argument must be of type 'string', 'number', or 'any'.
|
|
|
|
|
|
==== tests/cases/compiler/indexTypeCheck.ts (8 errors) ====
|
|
interface Red {
|
|
[n:number]; // ok
|
|
~~~~~~~~~~~
|
|
!!! error TS1021: An index signature must have a type annotation.
|
|
[s:string]; // ok
|
|
~~~~~~~~~~~
|
|
!!! error TS1021: An index signature must have a type annotation.
|
|
}
|
|
|
|
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
|
|
~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2413: Numeric index type 'number' is not assignable to string index type 'string'.
|
|
[s:string]: string; // error
|
|
}
|
|
|
|
interface Green {
|
|
[n:number]: Orange; // error
|
|
~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2413: Numeric index type 'Orange' is not assignable to string index type 'Yellow'.
|
|
[s:string]: Yellow; // ok
|
|
}
|
|
|
|
interface Cyan {
|
|
[n:number]: number; // error
|
|
~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2413: Numeric index type 'number' is not assignable to string index type 'string'.
|
|
[s:string]: string; // ok
|
|
}
|
|
|
|
interface Purple {
|
|
[n:number, s:string]; // error
|
|
~
|
|
!!! error TS1096: An index signature must have exactly one parameter.
|
|
}
|
|
|
|
interface Magenta {
|
|
[p:Purple]; // error
|
|
~
|
|
!!! error TS1023: An index signature parameter type must be 'string' or 'number'.
|
|
}
|
|
|
|
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
|
|
~~~~~~~~~~~~
|
|
!!! error TS2342: An index expression argument must be of type 'string', 'number', or 'any'.
|
|
|
|
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];
|
|
}
|
|
} |