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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(12,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'.
Type 'T' is not assignable to type 'U'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(17,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'.
Type 'T' is not assignable to type 'U'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(21,5): error TS2536: Type 'keyof U' cannot be used to index type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(22,12): error TS2536: Type 'keyof U' cannot be used to index type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(26,5): error TS2536: Type 'K' cannot be used to index type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(27,12): error TS2536: Type 'K' cannot be used to index type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(31,5): error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'.
Type 'undefined' is not assignable to type 'T[keyof T]'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(36,5): error TS2322: Type 'T[K] | undefined' is not assignable to type 'T[K]'.
Type 'undefined' is not assignable to type 'T[K]'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(41,5): error TS2322: Type 'U[keyof T] | undefined' is not assignable to type 'T[keyof T]'.
Type 'undefined' is not assignable to type 'T[keyof T]'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(42,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T] | undefined'.
Type 'T[keyof T]' is not assignable to type 'U[keyof T]'.
Type 'T' is not assignable to type 'U'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(46,5): error TS2322: Type 'U[K] | undefined' is not assignable to type 'T[K]'.
Type 'undefined' is not assignable to type 'T[K]'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(47,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'.
Type 'T[K]' is not assignable to type 'U[K]'.
Type 'T' is not assignable to type 'U'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(52,5): error TS2542: Index signature in type 'Readonly<T>' only permits reading.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(57,5): error TS2542: Index signature in type 'Readonly<T>' only permits reading.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(62,5): error TS2542: Index signature in type 'Readonly<U>' only permits reading.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(67,5): error TS2542: Index signature in type 'Readonly<U>' only permits reading.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(71,5): error TS2322: Type 'Partial<T>' is not assignable to type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(76,5): error TS2322: Type 'Partial<T>' is not assignable to type 'T'.
==== tests/cases/conformance/types/mapped/mappedTypeRelationships.ts (18 errors) ====
function f1<T>(x: T, k: keyof T) {
return x[k];
}
function f2<T, K extends keyof T>(x: T, k: K) {
return x[k];
}
function f3<T, U extends T>(x: T, y: U, k: keyof T) {
x[k] = y[k];
y[k] = x[k]; // Error
~~~~
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
}
function f4<T, U extends T, K extends keyof T>(x: T, y: U, k: K) {
x[k] = y[k];
y[k] = x[k]; // Error
~~~~
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
}
function f5<T, U extends T>(x: T, y: U, k: keyof U) {
x[k] = y[k]; // Error
~~~~
!!! error TS2536: Type 'keyof U' cannot be used to index type 'T'.
y[k] = x[k]; // Error
~~~~
!!! error TS2536: Type 'keyof U' cannot be used to index type 'T'.
}
function f6<T, U extends T, K extends keyof U>(x: T, y: U, k: K) {
x[k] = y[k]; // Error
~~~~
!!! error TS2536: Type 'K' cannot be used to index type 'T'.
y[k] = x[k]; // Error
~~~~
!!! error TS2536: Type 'K' cannot be used to index type 'T'.
}
function f10<T>(x: T, y: Partial<T>, k: keyof T) {
x[k] = y[k]; // Error
~~~~
!!! error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'.
!!! error TS2322: Type 'undefined' is not assignable to type 'T[keyof T]'.
y[k] = x[k];
}
function f11<T, K extends keyof T>(x: T, y: Partial<T>, k: K) {
x[k] = y[k]; // Error
~~~~
!!! error TS2322: Type 'T[K] | undefined' is not assignable to type 'T[K]'.
!!! error TS2322: Type 'undefined' is not assignable to type 'T[K]'.
y[k] = x[k];
}
function f12<T, U extends T>(x: T, y: Partial<U>, k: keyof T) {
x[k] = y[k]; // Error
~~~~
!!! error TS2322: Type 'U[keyof T] | undefined' is not assignable to type 'T[keyof T]'.
!!! error TS2322: Type 'undefined' is not assignable to type 'T[keyof T]'.
y[k] = x[k]; // Error
~~~~
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T] | undefined'.
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
}
function f13<T, U extends T, K extends keyof T>(x: T, y: Partial<U>, k: K) {
x[k] = y[k]; // Error
~~~~
!!! error TS2322: Type 'U[K] | undefined' is not assignable to type 'T[K]'.
!!! error TS2322: Type 'undefined' is not assignable to type 'T[K]'.
y[k] = x[k]; // Error
~~~~
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'.
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
}
function f20<T>(x: T, y: Readonly<T>, k: keyof T) {
x[k] = y[k];
y[k] = x[k]; // Error
~~~~
!!! error TS2542: Index signature in type 'Readonly<T>' only permits reading.
}
function f21<T, K extends keyof T>(x: T, y: Readonly<T>, k: K) {
x[k] = y[k];
y[k] = x[k]; // Error
~~~~
!!! error TS2542: Index signature in type 'Readonly<T>' only permits reading.
}
function f22<T, U extends T>(x: T, y: Readonly<U>, k: keyof T) {
x[k] = y[k];
y[k] = x[k]; // Error
~~~~
!!! error TS2542: Index signature in type 'Readonly<U>' only permits reading.
}
function f23<T, U extends T, K extends keyof T>(x: T, y: Readonly<U>, k: K) {
x[k] = y[k];
y[k] = x[k]; // Error
~~~~
!!! error TS2542: Index signature in type 'Readonly<U>' only permits reading.
}
function f30<T>(x: T, y: Partial<T>) {
x = y; // Error
~
!!! error TS2322: Type 'Partial<T>' is not assignable to type 'T'.
y = x;
}
function f31<T>(x: T, y: Partial<T>) {
x = y; // Error
~
!!! error TS2322: Type 'Partial<T>' is not assignable to type 'T'.
y = x;
}
function f40<T>(x: T, y: Readonly<T>) {
x = y;
y = x;
}
function f41<T>(x: T, y: Readonly<T>) {
x = y;
y = x;
}
type Item = {
name: string;
}
type ItemMap = {
[x: string]: Item;
}
function f50<T extends ItemMap>(obj: T, key: keyof T) {
let item: Item = obj[key];
return obj[key].name;
}
function f51<T extends ItemMap, K extends keyof T>(obj: T, key: K) {
let item: Item = obj[key];
return obj[key].name;
}
|