|
| 1 | +tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(43,5): error TS2322: Type 'Obj' is not assignable to type 'NumberTo<any>'. |
| 2 | + Index signature is missing in type 'Obj'. |
| 3 | +tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(49,5): error TS2739: Type 'StringTo<any>' is missing the following properties from type 'Obj': hello, world |
| 4 | +tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(50,5): error TS2739: Type 'NumberTo<any>' is missing the following properties from type 'Obj': hello, world |
| 5 | +tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(51,5): error TS2739: Type 'StringAndNumberTo<any>' is missing the following properties from type 'Obj': hello, world |
| 6 | +tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(61,5): error TS2322: Type 'Obj' is not assignable to type 'NumberTo<any>'. |
| 7 | +tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(65,5): error TS2322: Type 'Obj' is not assignable to type 'StringTo<any> & NumberTo<any>'. |
| 8 | + Type 'Obj' is not assignable to type 'NumberTo<any>'. |
| 9 | + Index signature is missing in type 'Obj'. |
| 10 | +tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(67,5): error TS2322: Type 'StringTo<any>' is not assignable to type 'Obj'. |
| 11 | +tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(68,5): error TS2322: Type 'NumberTo<any>' is not assignable to type 'Obj'. |
| 12 | +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 |
| 13 | +tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(84,5): error TS2322: Type 'Obj' is not assignable to type 'NumberToNumber'. |
| 14 | + Index signature is missing in type 'Obj'. |
| 15 | +tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(88,5): error TS2322: Type 'Obj' is not assignable to type 'StringToAnyNumberToNumber'. |
| 16 | + Index signature is missing in type 'Obj'. |
| 17 | +tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(90,5): error TS2322: Type 'StringTo<any>' is not assignable to type 'Obj'. |
| 18 | +tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts(91,5): error TS2739: Type 'NumberTo<number>' is missing the following properties from type 'Obj': hello, world |
| 19 | + |
| 20 | + |
| 21 | +==== tests/cases/conformance/types/members/objectTypeWithStringAndNumberIndexSignatureToAny.ts (13 errors) ==== |
| 22 | + // When checking compatibility between two types, |
| 23 | + // TypeScript should not require an index signature if |
| 24 | + // the target side index signature maps to `any` *and* |
| 25 | + // the target side has *any* string index signature to `any`. |
| 26 | + // |
| 27 | + // So an index signature like in |
| 28 | + // |
| 29 | + // { [x: number]: any } |
| 30 | + // |
| 31 | + // is still required of a source type, but neither index signature in |
| 32 | + // |
| 33 | + // { [x: number]: any, [x: string]: any; } |
| 34 | + // |
| 35 | + // should be required; *however*, the number index signature in |
| 36 | + // |
| 37 | + // { [x: number]: number, [x: string]: any; } |
| 38 | + // |
| 39 | + // should always be required. |
| 40 | + |
| 41 | + interface StringTo<T> { |
| 42 | + [x: string]: T; |
| 43 | + } |
| 44 | + |
| 45 | + interface NumberTo<T> { |
| 46 | + [x: number]: T; |
| 47 | + } |
| 48 | + |
| 49 | + interface StringAndNumberTo<T> extends StringTo<T>, NumberTo<T> { |
| 50 | + } |
| 51 | + |
| 52 | + interface Obj { |
| 53 | + hello: string; |
| 54 | + world: number; |
| 55 | + } |
| 56 | + |
| 57 | + function f1(sToAny: StringTo<any>, nToAny: NumberTo<any>, bothToAny: StringAndNumberTo<any>, someObj: Obj) { |
| 58 | + sToAny = nToAny; |
| 59 | + sToAny = bothToAny; |
| 60 | + sToAny = someObj; |
| 61 | + |
| 62 | + nToAny = sToAny; |
| 63 | + nToAny = bothToAny; |
| 64 | + nToAny = someObj; |
| 65 | + ~~~~~~ |
| 66 | +!!! error TS2322: Type 'Obj' is not assignable to type 'NumberTo<any>'. |
| 67 | +!!! error TS2322: Index signature is missing in type 'Obj'. |
| 68 | + |
| 69 | + bothToAny = sToAny; |
| 70 | + bothToAny = nToAny; |
| 71 | + bothToAny = someObj; |
| 72 | + |
| 73 | + someObj = sToAny; |
| 74 | + ~~~~~~~ |
| 75 | +!!! error TS2739: Type 'StringTo<any>' is missing the following properties from type 'Obj': hello, world |
| 76 | + someObj = nToAny; |
| 77 | + ~~~~~~~ |
| 78 | +!!! error TS2739: Type 'NumberTo<any>' is missing the following properties from type 'Obj': hello, world |
| 79 | + someObj = bothToAny; |
| 80 | + ~~~~~~~ |
| 81 | +!!! error TS2739: Type 'StringAndNumberTo<any>' is missing the following properties from type 'Obj': hello, world |
| 82 | + } |
| 83 | + |
| 84 | + function f2(sToAny: StringTo<any>, nToAny: NumberTo<any>, bothToAny: StringTo<any> & NumberTo<any>, someObj: Obj) { |
| 85 | + sToAny = nToAny; |
| 86 | + sToAny = bothToAny; |
| 87 | + sToAny = someObj; |
| 88 | + |
| 89 | + nToAny = sToAny; |
| 90 | + nToAny = bothToAny; |
| 91 | + nToAny = someObj; |
| 92 | + ~~~~~~ |
| 93 | +!!! error TS2322: Type 'Obj' is not assignable to type 'NumberTo<any>'. |
| 94 | + |
| 95 | + bothToAny = sToAny; |
| 96 | + bothToAny = nToAny; |
| 97 | + bothToAny = someObj; |
| 98 | + ~~~~~~~~~ |
| 99 | +!!! error TS2322: Type 'Obj' is not assignable to type 'StringTo<any> & NumberTo<any>'. |
| 100 | +!!! error TS2322: Type 'Obj' is not assignable to type 'NumberTo<any>'. |
| 101 | +!!! error TS2322: Index signature is missing in type 'Obj'. |
| 102 | + |
| 103 | + someObj = sToAny; |
| 104 | + ~~~~~~~ |
| 105 | +!!! error TS2322: Type 'StringTo<any>' is not assignable to type 'Obj'. |
| 106 | + someObj = nToAny; |
| 107 | + ~~~~~~~ |
| 108 | +!!! error TS2322: Type 'NumberTo<any>' is not assignable to type 'Obj'. |
| 109 | + someObj = bothToAny; |
| 110 | + ~~~~~~~ |
| 111 | +!!! error TS2739: Type 'StringTo<any> & NumberTo<any>' is missing the following properties from type 'Obj': hello, world |
| 112 | + } |
| 113 | + |
| 114 | + type NumberToNumber = NumberTo<number>; |
| 115 | + |
| 116 | + interface StringToAnyNumberToNumber extends StringTo<any>, NumberToNumber { |
| 117 | + } |
| 118 | + |
| 119 | + function f3(sToAny: StringTo<any>, nToNumber: NumberToNumber, strToAnyNumToNum: StringToAnyNumberToNumber, someObj: Obj) { |
| 120 | + sToAny = nToNumber; |
| 121 | + sToAny = strToAnyNumToNum; |
| 122 | + sToAny = someObj; |
| 123 | + |
| 124 | + nToNumber = sToAny; |
| 125 | + nToNumber = strToAnyNumToNum; |
| 126 | + nToNumber = someObj; |
| 127 | + ~~~~~~~~~ |
| 128 | +!!! error TS2322: Type 'Obj' is not assignable to type 'NumberToNumber'. |
| 129 | +!!! error TS2322: Index signature is missing in type 'Obj'. |
| 130 | + |
| 131 | + strToAnyNumToNum = sToAny; |
| 132 | + strToAnyNumToNum = nToNumber; |
| 133 | + strToAnyNumToNum = someObj; |
| 134 | + ~~~~~~~~~~~~~~~~ |
| 135 | +!!! error TS2322: Type 'Obj' is not assignable to type 'StringToAnyNumberToNumber'. |
| 136 | +!!! error TS2322: Index signature is missing in type 'Obj'. |
| 137 | + |
| 138 | + someObj = sToAny; |
| 139 | + ~~~~~~~ |
| 140 | +!!! error TS2322: Type 'StringTo<any>' is not assignable to type 'Obj'. |
| 141 | + someObj = nToNumber; |
| 142 | + ~~~~~~~ |
| 143 | +!!! error TS2739: Type 'NumberTo<number>' is missing the following properties from type 'Obj': hello, world |
| 144 | + someObj = someObj; |
| 145 | + } |
0 commit comments