File: indexerConstraints2.errors.txt

package info (click to toggle)
node-typescript 4.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 396,552 kB
  • sloc: javascript: 1,444,377; makefile: 7; sh: 3
file content (120 lines) | stat: -rw-r--r-- 4,823 bytes parent folder | download
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
tests/cases/compiler/indexerConstraints2.ts(9,5): error TS2413: Numeric index type 'A' is not assignable to string index type 'B'.
tests/cases/compiler/indexerConstraints2.ts(17,5): error TS2413: Numeric index type 'A' is not assignable to string index type 'B'.
tests/cases/compiler/indexerConstraints2.ts(26,5): error TS2413: Numeric index type 'A' is not assignable to string index type 'B'.
tests/cases/compiler/indexerConstraints2.ts(34,6): error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[n: number]: A' instead.
tests/cases/compiler/indexerConstraints2.ts(40,6): error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[s: string]: A' instead.
tests/cases/compiler/indexerConstraints2.ts(46,6): error TS1023: An index signature parameter type must be either 'string' or 'number'.
tests/cases/compiler/indexerConstraints2.ts(52,6): error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
tests/cases/compiler/indexerConstraints2.ts(58,6): error TS1023: An index signature parameter type must be either 'string' or 'number'.
tests/cases/compiler/indexerConstraints2.ts(64,6): error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
tests/cases/compiler/indexerConstraints2.ts(70,6): error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
tests/cases/compiler/indexerConstraints2.ts(74,6): error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
tests/cases/compiler/indexerConstraints2.ts(79,6): error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[key: string]: any' instead.


==== tests/cases/compiler/indexerConstraints2.ts (12 errors) ====
    class A { a: number; }
    class B extends A { b: number; }
    
    // Inheritance
    class F {
        [s: string]: B
    }
    class G extends F {
        [n: number]: A
        ~~~~~~~~~~~~~~
!!! error TS2413: Numeric index type 'A' is not assignable to string index type 'B'.
    }
    
    // Other way
    class H {
        [n: number]: A
    }
    class I extends H {
        [s: string]: B
        ~~~~~~~~~~~~~~
!!! error TS2413: Numeric index type 'A' is not assignable to string index type 'B'.
    }
    
    // With hidden indexer
    class J {
        [n: number]: {}
    }
    
    class K extends J {
        [n: number]: A;
        ~~~~~~~~~~~~~~~
!!! error TS2413: Numeric index type 'A' is not assignable to string index type 'B'.
        [s: string]: B;
    }
    
    
    type AliasedNumber = number;
    
    interface L {
        [n: AliasedNumber]: A;
         ~
!!! error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[n: number]: A' instead.
    }
    
    type AliasedString = string;
    
    interface M {
        [s: AliasedString]: A;
         ~
!!! error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[s: string]: A' instead.
    }
    
    type AliasedBoolean = boolean;
    
    interface N {
        [b: AliasedBoolean]: A;
         ~
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'.
    }
    
    type IndexableUnion = "foo" | "bar";
    
    interface O {
        [u: IndexableUnion]: A;
         ~
!!! error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
    }
    
    type NonIndexableUnion = boolean | {};
    
    interface P {
        [u: NonIndexableUnion]: A;
         ~
!!! error TS1023: An index signature parameter type must be either 'string' or 'number'.
    }
    
    type NonIndexableUnion2 = string | number;
    
    interface Q {
        [u: NonIndexableUnion2]: A;
         ~
!!! error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
    }
    
    type NonIndexableUnion3 = "foo" | 42;
    
    interface R {
        [u: NonIndexableUnion3]: A;
         ~
!!! error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
    }
    
    interface S {
        [u: "foo" | "bar"]: A;
         ~
!!! error TS1337: An index signature parameter type cannot be a union type. Consider using a mapped object type instead.
    }
    
    type Key = string;
    interface T {
        [key: Key]
         ~~~
!!! error TS1336: An index signature parameter type cannot be a type alias. Consider writing '[key: string]: any' instead.
    }