File: indexTypeCheck.errors.txt

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (90 lines) | stat: -rw-r--r-- 3,178 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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: 'number' index type 'number' is not assignable to 'string' index type 'string'.
tests/cases/compiler/indexTypeCheck.ts(22,2): error TS2413: 'number' index type 'Orange' is not assignable to 'string' index type 'Yellow'.
tests/cases/compiler/indexTypeCheck.ts(27,2): error TS2413: 'number' 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 TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
tests/cases/compiler/indexTypeCheck.ts(51,8): error TS2538: Type 'Blue' cannot be used as an index type.


==== 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: 'number' index type 'number' is not assignable to 'string' index type 'string'.
    	[s:string]: string; // error
    }
    
    interface Green {
    	[n:number]: Orange; // error
    	~~~~~~~~~~~~~~~~~~~
!!! error TS2413: 'number' index type 'Orange' is not assignable to 'string' index type 'Yellow'.
    	[s:string]: Yellow; // ok
    }
    
    interface Cyan {
    	[n:number]: number; // error
    	~~~~~~~~~~~~~~~~~~~
!!! error TS2413: 'number' 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 TS1268: An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type.
    }
    
    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 TS2538: Type 'Blue' cannot be used as an index type.
    
    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];
        }
    }