File: objectTypeWithStringAndNumberIndexSignatureToAny.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 (145 lines) | stat: -rw-r--r-- 7,216 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(43,5): error TS2322: Type 'Obj' is not assignable to type 'NumberTo<any>'.
  Index signature for type 'number' is missing in type 'Obj'.
tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(49,5): error TS2739: Type 'StringTo<any>' is missing the following properties from type 'Obj': hello, world
tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(50,5): error TS2739: Type 'NumberTo<any>' is missing the following properties from type 'Obj': hello, world
tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(51,5): error TS2739: Type 'StringAndNumberTo<any>' is missing the following properties from type 'Obj': hello, world
tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(61,5): error TS2322: Type 'Obj' is not assignable to type 'NumberTo<any>'.
tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(65,5): error TS2322: Type 'Obj' is not assignable to type 'StringTo<any> & NumberTo<any>'.
  Type 'Obj' is not assignable to type 'NumberTo<any>'.
    Index signature for type 'number' is missing in type 'Obj'.
tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(67,5): error TS2322: Type 'StringTo<any>' is not assignable to type 'Obj'.
tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(68,5): error TS2322: Type 'NumberTo<any>' is not assignable to type 'Obj'.
tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(69,5): error TS2739: Type 'StringTo<any> & NumberTo<any>' is missing the following properties from type 'Obj': hello, world
tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(84,5): error TS2322: Type 'Obj' is not assignable to type 'NumberToNumber'.
  Index signature for type 'number' is missing in type 'Obj'.
tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(88,5): error TS2322: Type 'Obj' is not assignable to type 'StringToAnyNumberToNumber'.
  Index signature for type 'number' is missing in type 'Obj'.
tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(90,5): error TS2322: Type 'StringTo<any>' is not assignable to type 'Obj'.
tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(91,5): error TS2739: Type 'NumberTo<number>' is missing the following properties from type 'Obj': hello, world


==== tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts (13 errors) ====
    // When checking compatibility between two types,
    // TypeScript should not require an index signature if
    // the target side index signature maps to `any` *and*
    // the target side has *any* string index signature to `any`.
    //
    // So an index signature like in
    //
    //  { [x: number]: any }
    //
    // is still required of a source type, but neither index signature in
    //
    //  { [x: number]: any, [x: string]: any; }
    //
    // should be required; *however*, the number index signature in
    //
    //  { [x: number]: number, [x: string]: any; }
    //
    // should always be required.
    
    interface StringTo<T> {
        [x: string]: T;
    }
    
    interface NumberTo<T> {
        [x: number]: T;
    }
    
    interface StringAndNumberTo<T> extends StringTo<T>, NumberTo<T> {
    }
    
    interface Obj {
        hello: string;
        world: number;
    }
    
    function f1(sToAny: StringTo<any>, nToAny: NumberTo<any>, bothToAny: StringAndNumberTo<any>, someObj: Obj) {
        sToAny = nToAny;
        sToAny = bothToAny;
        sToAny = someObj;
    
        nToAny = sToAny;
        nToAny = bothToAny;
        nToAny = someObj;
        ~~~~~~
!!! error TS2322: Type 'Obj' is not assignable to type 'NumberTo<any>'.
!!! error TS2322:   Index signature for type 'number' is missing in type 'Obj'.
    
        bothToAny = sToAny;
        bothToAny = nToAny;
        bothToAny = someObj;
    
        someObj = sToAny;
        ~~~~~~~
!!! error TS2739: Type 'StringTo<any>' is missing the following properties from type 'Obj': hello, world
        someObj = nToAny;
        ~~~~~~~
!!! error TS2739: Type 'NumberTo<any>' is missing the following properties from type 'Obj': hello, world
        someObj = bothToAny;
        ~~~~~~~
!!! error TS2739: Type 'StringAndNumberTo<any>' is missing the following properties from type 'Obj': hello, world
    }
    
    function f2(sToAny: StringTo<any>, nToAny: NumberTo<any>, bothToAny: StringTo<any> & NumberTo<any>, someObj: Obj) {
        sToAny = nToAny;
        sToAny = bothToAny;
        sToAny = someObj;
    
        nToAny = sToAny;
        nToAny = bothToAny;
        nToAny = someObj;
        ~~~~~~
!!! error TS2322: Type 'Obj' is not assignable to type 'NumberTo<any>'.
    
        bothToAny = sToAny;
        bothToAny = nToAny;
        bothToAny = someObj;
        ~~~~~~~~~
!!! error TS2322: Type 'Obj' is not assignable to type 'StringTo<any> & NumberTo<any>'.
!!! error TS2322:   Type 'Obj' is not assignable to type 'NumberTo<any>'.
!!! error TS2322:     Index signature for type 'number' is missing in type 'Obj'.
    
        someObj = sToAny;
        ~~~~~~~
!!! error TS2322: Type 'StringTo<any>' is not assignable to type 'Obj'.
        someObj = nToAny;
        ~~~~~~~
!!! error TS2322: Type 'NumberTo<any>' is not assignable to type 'Obj'.
        someObj = bothToAny;
        ~~~~~~~
!!! error TS2739: Type 'StringTo<any> & NumberTo<any>' is missing the following properties from type 'Obj': hello, world
    }
    
    type NumberToNumber = NumberTo<number>;
    
    interface StringToAnyNumberToNumber extends StringTo<any>, NumberToNumber {
    }
    
    function f3(sToAny: StringTo<any>, nToNumber: NumberToNumber, strToAnyNumToNum: StringToAnyNumberToNumber, someObj: Obj) {
        sToAny = nToNumber;
        sToAny = strToAnyNumToNum;
        sToAny = someObj;
    
        nToNumber = sToAny;
        nToNumber = strToAnyNumToNum;
        nToNumber = someObj;
        ~~~~~~~~~
!!! error TS2322: Type 'Obj' is not assignable to type 'NumberToNumber'.
!!! error TS2322:   Index signature for type 'number' is missing in type 'Obj'.
    
        strToAnyNumToNum = sToAny;
        strToAnyNumToNum = nToNumber;
        strToAnyNumToNum = someObj;
        ~~~~~~~~~~~~~~~~
!!! error TS2322: Type 'Obj' is not assignable to type 'StringToAnyNumberToNumber'.
!!! error TS2322:   Index signature for type 'number' is missing in type 'Obj'.
    
        someObj = sToAny;
        ~~~~~~~
!!! error TS2322: Type 'StringTo<any>' is not assignable to type 'Obj'.
        someObj = nToNumber;
        ~~~~~~~
!!! error TS2739: Type 'NumberTo<number>' is missing the following properties from type 'Obj': hello, world
        someObj = someObj;
    }