|
| 1 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(23,5): error TS2322: Type 'T' is not assignable to type 'Required<T>'. |
| 2 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(24,5): error TS2322: Type 'Partial<T>' is not assignable to type 'Required<T>'. |
| 3 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(27,5): error TS2322: Type 'Partial<T>' is not assignable to type 'T'. |
| 4 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(37,5): error TS2322: Type 'Required<T>' is not assignable to type 'Denullified<T>'. |
| 5 | + Type 'T[P]' is not assignable to type 'NonNullable<T[P]>'. |
| 6 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(38,5): error TS2322: Type 'T' is not assignable to type 'Denullified<T>'. |
| 7 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(39,5): error TS2322: Type 'Partial<T>' is not assignable to type 'Denullified<T>'. |
| 8 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(42,5): error TS2322: Type 'T' is not assignable to type 'Required<T>'. |
| 9 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(43,5): error TS2322: Type 'Partial<T>' is not assignable to type 'Required<T>'. |
| 10 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(47,5): error TS2322: Type 'Partial<T>' is not assignable to type 'T'. |
| 11 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(56,5): error TS2322: Type '{}' is not assignable to type 'Denullified<T>'. |
| 12 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(57,5): error TS2322: Type '{}' is not assignable to type 'Required<T>'. |
| 13 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(58,5): error TS2322: Type '{}' is not assignable to type 'T'. |
| 14 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(92,1): error TS2322: Type '{ a: number; }' is not assignable to type 'Foo'. |
| 15 | + Property 'b' is missing in type '{ a: number; }'. |
| 16 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(104,1): error TS2322: Type '{ a: number; }' is not assignable to type 'Required<Foo>'. |
| 17 | + Property 'b' is missing in type '{ a: number; }'. |
| 18 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(105,1): error TS2322: Type '{ a: number; b: number; }' is not assignable to type 'Required<Foo>'. |
| 19 | + Property 'c' is missing in type '{ a: number; b: number; }'. |
| 20 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(106,1): error TS2322: Type '{ a: number; b: number; c: number; }' is not assignable to type 'Required<Foo>'. |
| 21 | + Property 'd' is missing in type '{ a: number; b: number; c: number; }'. |
| 22 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(116,4): error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. |
| 23 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(119,4): error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. |
| 24 | +tests/cases/conformance/types/mapped/mappedTypes6.ts(120,4): error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. |
| 25 | + |
| 26 | + |
| 27 | +==== tests/cases/conformance/types/mapped/mappedTypes6.ts (19 errors) ==== |
| 28 | + type T00<T> = { [P in keyof T]: T[P] }; |
| 29 | + type T01<T> = { [P in keyof T]?: T[P] }; |
| 30 | + type T02<T> = { [P in keyof T]+?: T[P] }; |
| 31 | + type T03<T> = { [P in keyof T]-?: T[P] }; |
| 32 | + |
| 33 | + type T04<T> = { readonly [P in keyof T]: T[P] }; |
| 34 | + type T05<T> = { readonly [P in keyof T]?: T[P] }; |
| 35 | + type T06<T> = { readonly [P in keyof T]+?: T[P] }; |
| 36 | + type T07<T> = { readonly [P in keyof T]-?: T[P] }; |
| 37 | + |
| 38 | + type T08<T> = { +readonly [P in keyof T]: T[P] }; |
| 39 | + type T09<T> = { +readonly [P in keyof T]?: T[P] }; |
| 40 | + type T10<T> = { +readonly [P in keyof T]+?: T[P] }; |
| 41 | + type T11<T> = { +readonly [P in keyof T]-?: T[P] }; |
| 42 | + |
| 43 | + type T12<T> = { -readonly [P in keyof T]: T[P] }; |
| 44 | + type T13<T> = { -readonly [P in keyof T]?: T[P] }; |
| 45 | + type T14<T> = { -readonly [P in keyof T]+?: T[P] }; |
| 46 | + type T15<T> = { -readonly [P in keyof T]-?: T[P] }; |
| 47 | + |
| 48 | + function f1<T>(x: Required<T>, y: T, z: Partial<T>) { |
| 49 | + x = x; |
| 50 | + x = y; // Error |
| 51 | + ~ |
| 52 | +!!! error TS2322: Type 'T' is not assignable to type 'Required<T>'. |
| 53 | + x = z; // Error |
| 54 | + ~ |
| 55 | +!!! error TS2322: Type 'Partial<T>' is not assignable to type 'Required<T>'. |
| 56 | + y = x; |
| 57 | + y = y; |
| 58 | + y = z; // Error |
| 59 | + ~ |
| 60 | +!!! error TS2322: Type 'Partial<T>' is not assignable to type 'T'. |
| 61 | + z = x; |
| 62 | + z = y; |
| 63 | + z = z; |
| 64 | + } |
| 65 | + |
| 66 | + type Denullified<T> = { [P in keyof T]-?: NonNullable<T[P]> }; |
| 67 | + |
| 68 | + function f2<T>(w: Denullified<T>, x: Required<T>, y: T, z: Partial<T>) { |
| 69 | + w = w; |
| 70 | + w = x; // Error |
| 71 | + ~ |
| 72 | +!!! error TS2322: Type 'Required<T>' is not assignable to type 'Denullified<T>'. |
| 73 | +!!! error TS2322: Type 'T[P]' is not assignable to type 'NonNullable<T[P]>'. |
| 74 | + w = y; // Error |
| 75 | + ~ |
| 76 | +!!! error TS2322: Type 'T' is not assignable to type 'Denullified<T>'. |
| 77 | + w = z; // Error |
| 78 | + ~ |
| 79 | +!!! error TS2322: Type 'Partial<T>' is not assignable to type 'Denullified<T>'. |
| 80 | + x = w; |
| 81 | + x = x; |
| 82 | + x = y; // Error |
| 83 | + ~ |
| 84 | +!!! error TS2322: Type 'T' is not assignable to type 'Required<T>'. |
| 85 | + x = z; // Error |
| 86 | + ~ |
| 87 | +!!! error TS2322: Type 'Partial<T>' is not assignable to type 'Required<T>'. |
| 88 | + y = w; |
| 89 | + y = x; |
| 90 | + y = y; |
| 91 | + y = z; // Error |
| 92 | + ~ |
| 93 | +!!! error TS2322: Type 'Partial<T>' is not assignable to type 'T'. |
| 94 | + z = w; |
| 95 | + z = x; |
| 96 | + z = y; |
| 97 | + z = z; |
| 98 | + } |
| 99 | + |
| 100 | + |
| 101 | + function f3<T>(w: Denullified<T>, x: Required<T>, y: T, z: Partial<T>) { |
| 102 | + w = {}; // Error |
| 103 | + ~ |
| 104 | +!!! error TS2322: Type '{}' is not assignable to type 'Denullified<T>'. |
| 105 | + x = {}; // Error |
| 106 | + ~ |
| 107 | +!!! error TS2322: Type '{}' is not assignable to type 'Required<T>'. |
| 108 | + y = {}; // Error |
| 109 | + ~ |
| 110 | +!!! error TS2322: Type '{}' is not assignable to type 'T'. |
| 111 | + z = {}; |
| 112 | + } |
| 113 | + |
| 114 | + type Readwrite<T> = { |
| 115 | + -readonly [P in keyof T]: T[P]; |
| 116 | + } |
| 117 | + |
| 118 | + function f10<T>(x: Readonly<T>, y: T, z: Readwrite<T>) { |
| 119 | + x = x; |
| 120 | + x = y; |
| 121 | + x = z; |
| 122 | + y = x; |
| 123 | + y = y; |
| 124 | + y = z; |
| 125 | + z = x; |
| 126 | + z = y; |
| 127 | + z = z; |
| 128 | + } |
| 129 | + |
| 130 | + type Foo = { |
| 131 | + a: number; |
| 132 | + b: number | undefined; |
| 133 | + c?: number; |
| 134 | + d?: number | undefined; |
| 135 | + } |
| 136 | + |
| 137 | + declare let x1: Foo; |
| 138 | + |
| 139 | + x1.a; // number |
| 140 | + x1.b; // number | undefined |
| 141 | + x1.c; // number | undefined |
| 142 | + x1.d; // number | undefined |
| 143 | + |
| 144 | + x1 = { a: 1 }; // Error |
| 145 | + ~~ |
| 146 | +!!! error TS2322: Type '{ a: number; }' is not assignable to type 'Foo'. |
| 147 | +!!! error TS2322: Property 'b' is missing in type '{ a: number; }'. |
| 148 | + x1 = { a: 1, b: 1 }; |
| 149 | + x1 = { a: 1, b: 1, c: 1 }; |
| 150 | + x1 = { a: 1, b: 1, c: 1, d: 1 }; |
| 151 | + |
| 152 | + declare let x2: Required<Foo>; |
| 153 | + |
| 154 | + x1.a; // number |
| 155 | + x1.b; // number | undefined |
| 156 | + x1.c; // number |
| 157 | + x1.d; // number |
| 158 | + |
| 159 | + x2 = { a: 1 }; // Error |
| 160 | + ~~ |
| 161 | +!!! error TS2322: Type '{ a: number; }' is not assignable to type 'Required<Foo>'. |
| 162 | +!!! error TS2322: Property 'b' is missing in type '{ a: number; }'. |
| 163 | + x2 = { a: 1, b: 1 }; // Error |
| 164 | + ~~ |
| 165 | +!!! error TS2322: Type '{ a: number; b: number; }' is not assignable to type 'Required<Foo>'. |
| 166 | +!!! error TS2322: Property 'c' is missing in type '{ a: number; b: number; }'. |
| 167 | + x2 = { a: 1, b: 1, c: 1 }; // Error |
| 168 | + ~~ |
| 169 | +!!! error TS2322: Type '{ a: number; b: number; c: number; }' is not assignable to type 'Required<Foo>'. |
| 170 | +!!! error TS2322: Property 'd' is missing in type '{ a: number; b: number; c: number; }'. |
| 171 | + x2 = { a: 1, b: 1, c: 1, d: 1 }; |
| 172 | + |
| 173 | + type Bar = { |
| 174 | + a: number; |
| 175 | + readonly b: number; |
| 176 | + } |
| 177 | + |
| 178 | + declare let x3: Bar; |
| 179 | + x3.a = 1; |
| 180 | + x3.b = 1; // Error |
| 181 | + ~ |
| 182 | +!!! error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. |
| 183 | + |
| 184 | + declare let x4: Readonly<Bar>; |
| 185 | + x4.a = 1; // Error |
| 186 | + ~ |
| 187 | +!!! error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. |
| 188 | + x4.b = 1; // Error |
| 189 | + ~ |
| 190 | +!!! error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. |
| 191 | + |
| 192 | + declare let x5: Readwrite<Bar>; |
| 193 | + x5.a = 1; |
| 194 | + x5.b = 1; |
| 195 | + |
0 commit comments