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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
tests/cases/conformance/types/mapped/mappedTypes6.ts(23,5): error TS2322: Type 'T' is not assignable to type 'Required<T>'.
tests/cases/conformance/types/mapped/mappedTypes6.ts(24,5): error TS2322: Type 'Partial<T>' is not assignable to type 'Required<T>'.
tests/cases/conformance/types/mapped/mappedTypes6.ts(27,5): error TS2322: Type 'Partial<T>' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'Partial<T>'.
tests/cases/conformance/types/mapped/mappedTypes6.ts(37,5): error TS2322: Type 'Required<T>' is not assignable to type 'Denullified<T>'.
Type 'T[P]' is not assignable to type 'NonNullable<T[P]>'.
Type 'T[keyof T]' is not assignable to type 'NonNullable<T[P]>'.
Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'NonNullable<T[P]>'.
Type 'T[string]' is not assignable to type 'NonNullable<T[P]>'.
Type 'T[string]' is not assignable to type 'T[P]'.
Type 'string' is not assignable to type 'P'.
'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'.
Type 'T[keyof T]' is not assignable to type 'T[P]'.
Type 'keyof T' is not assignable to type 'P'.
'keyof T' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'.
Type 'string | number | symbol' is not assignable to type 'P'.
'string | number | symbol' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'.
Type 'string' is not assignable to type 'P'.
'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'.
Type 'T[P]' is not assignable to type '{}'.
Type 'T[keyof T]' is not assignable to type '{}'.
Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'.
Type 'T[string]' is not assignable to type '{}'.
tests/cases/conformance/types/mapped/mappedTypes6.ts(38,5): error TS2322: Type 'T' is not assignable to type 'Denullified<T>'.
tests/cases/conformance/types/mapped/mappedTypes6.ts(39,5): error TS2322: Type 'Partial<T>' is not assignable to type 'Denullified<T>'.
tests/cases/conformance/types/mapped/mappedTypes6.ts(42,5): error TS2322: Type 'T' is not assignable to type 'Required<T>'.
tests/cases/conformance/types/mapped/mappedTypes6.ts(43,5): error TS2322: Type 'Partial<T>' is not assignable to type 'Required<T>'.
tests/cases/conformance/types/mapped/mappedTypes6.ts(47,5): error TS2322: Type 'Partial<T>' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to 'Partial<T>'.
tests/cases/conformance/types/mapped/mappedTypes6.ts(56,5): error TS2322: Type '{}' is not assignable to type 'Denullified<T>'.
tests/cases/conformance/types/mapped/mappedTypes6.ts(57,5): error TS2322: Type '{}' is not assignable to type 'Required<T>'.
tests/cases/conformance/types/mapped/mappedTypes6.ts(58,5): error TS2322: Type '{}' is not assignable to type 'T'.
'T' could be instantiated with an arbitrary type which could be unrelated to '{}'.
tests/cases/conformance/types/mapped/mappedTypes6.ts(92,1): error TS2741: Property 'b' is missing in type '{ a: number; }' but required in type 'Foo'.
tests/cases/conformance/types/mapped/mappedTypes6.ts(104,1): error TS2739: Type '{ a: number; }' is missing the following properties from type 'Required<Foo>': b, c, d
tests/cases/conformance/types/mapped/mappedTypes6.ts(105,1): error TS2739: Type '{ a: number; b: number; }' is missing the following properties from type 'Required<Foo>': c, d
tests/cases/conformance/types/mapped/mappedTypes6.ts(106,1): error TS2741: Property 'd' is missing in type '{ a: number; b: number; c: number; }' but required in type 'Required<Foo>'.
tests/cases/conformance/types/mapped/mappedTypes6.ts(116,4): error TS2540: Cannot assign to 'b' because it is a read-only property.
tests/cases/conformance/types/mapped/mappedTypes6.ts(119,4): error TS2540: Cannot assign to 'a' because it is a read-only property.
tests/cases/conformance/types/mapped/mappedTypes6.ts(120,4): error TS2540: Cannot assign to 'b' because it is a read-only property.
==== tests/cases/conformance/types/mapped/mappedTypes6.ts (19 errors) ====
type T00<T> = { [P in keyof T]: T[P] };
type T01<T> = { [P in keyof T]?: T[P] };
type T02<T> = { [P in keyof T]+?: T[P] };
type T03<T> = { [P in keyof T]-?: T[P] };
type T04<T> = { readonly [P in keyof T]: T[P] };
type T05<T> = { readonly [P in keyof T]?: T[P] };
type T06<T> = { readonly [P in keyof T]+?: T[P] };
type T07<T> = { readonly [P in keyof T]-?: T[P] };
type T08<T> = { +readonly [P in keyof T]: T[P] };
type T09<T> = { +readonly [P in keyof T]?: T[P] };
type T10<T> = { +readonly [P in keyof T]+?: T[P] };
type T11<T> = { +readonly [P in keyof T]-?: T[P] };
type T12<T> = { -readonly [P in keyof T]: T[P] };
type T13<T> = { -readonly [P in keyof T]?: T[P] };
type T14<T> = { -readonly [P in keyof T]+?: T[P] };
type T15<T> = { -readonly [P in keyof T]-?: T[P] };
function f1<T>(x: Required<T>, y: T, z: Partial<T>) {
x = x;
x = y; // Error
~
!!! error TS2322: Type 'T' is not assignable to type 'Required<T>'.
!!! related TS2208 tests/cases/conformance/types/mapped/mappedTypes6.ts:21:13: This type parameter might need an `extends Required<T>` constraint.
x = z; // Error
~
!!! error TS2322: Type 'Partial<T>' is not assignable to type 'Required<T>'.
y = x;
y = y;
y = z; // Error
~
!!! error TS2322: Type 'Partial<T>' is not assignable to type 'T'.
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Partial<T>'.
z = x;
z = y;
z = z;
}
type Denullified<T> = { [P in keyof T]-?: NonNullable<T[P]> };
function f2<T>(w: Denullified<T>, x: Required<T>, y: T, z: Partial<T>) {
w = w;
w = x; // Error
~
!!! error TS2322: Type 'Required<T>' is not assignable to type 'Denullified<T>'.
!!! error TS2322: Type 'T[P]' is not assignable to type 'NonNullable<T[P]>'.
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'NonNullable<T[P]>'.
!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'NonNullable<T[P]>'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'NonNullable<T[P]>'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'T[P]'.
!!! error TS2322: Type 'string' is not assignable to type 'P'.
!!! error TS2322: 'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'.
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'T[P]'.
!!! error TS2322: Type 'keyof T' is not assignable to type 'P'.
!!! error TS2322: 'keyof T' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'.
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'P'.
!!! error TS2322: 'string | number | symbol' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'.
!!! error TS2322: Type 'string' is not assignable to type 'P'.
!!! error TS2322: 'string' is assignable to the constraint of type 'P', but 'P' could be instantiated with a different subtype of constraint 'string | number | symbol'.
!!! error TS2322: Type 'T[P]' is not assignable to type '{}'.
!!! error TS2322: Type 'T[keyof T]' is not assignable to type '{}'.
!!! error TS2322: Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'.
!!! error TS2322: Type 'T[string]' is not assignable to type '{}'.
w = y; // Error
~
!!! error TS2322: Type 'T' is not assignable to type 'Denullified<T>'.
!!! related TS2208 tests/cases/conformance/types/mapped/mappedTypes6.ts:35:13: This type parameter might need an `extends Denullified<T>` constraint.
w = z; // Error
~
!!! error TS2322: Type 'Partial<T>' is not assignable to type 'Denullified<T>'.
x = w;
x = x;
x = y; // Error
~
!!! error TS2322: Type 'T' is not assignable to type 'Required<T>'.
!!! related TS2208 tests/cases/conformance/types/mapped/mappedTypes6.ts:35:13: This type parameter might need an `extends Required<T>` constraint.
x = z; // Error
~
!!! error TS2322: Type 'Partial<T>' is not assignable to type 'Required<T>'.
y = w;
y = x;
y = y;
y = z; // Error
~
!!! error TS2322: Type 'Partial<T>' is not assignable to type 'T'.
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to 'Partial<T>'.
z = w;
z = x;
z = y;
z = z;
}
function f3<T>(w: Denullified<T>, x: Required<T>, y: T, z: Partial<T>) {
w = {}; // Error
~
!!! error TS2322: Type '{}' is not assignable to type 'Denullified<T>'.
x = {}; // Error
~
!!! error TS2322: Type '{}' is not assignable to type 'Required<T>'.
y = {}; // Error
~
!!! error TS2322: Type '{}' is not assignable to type 'T'.
!!! error TS2322: 'T' could be instantiated with an arbitrary type which could be unrelated to '{}'.
z = {};
}
type Readwrite<T> = {
-readonly [P in keyof T]: T[P];
}
function f10<T>(x: Readonly<T>, y: T, z: Readwrite<T>) {
x = x;
x = y;
x = z;
y = x;
y = y;
y = z;
z = x;
z = y;
z = z;
}
type Foo = {
a: number;
b: number | undefined;
c?: number;
d?: number | undefined;
}
declare let x1: Foo;
x1.a; // number
x1.b; // number | undefined
x1.c; // number | undefined
x1.d; // number | undefined
x1 = { a: 1 }; // Error
~~
!!! error TS2741: Property 'b' is missing in type '{ a: number; }' but required in type 'Foo'.
!!! related TS2728 tests/cases/conformance/types/mapped/mappedTypes6.ts:80:5: 'b' is declared here.
x1 = { a: 1, b: 1 };
x1 = { a: 1, b: 1, c: 1 };
x1 = { a: 1, b: 1, c: 1, d: 1 };
declare let x2: Required<Foo>;
x1.a; // number
x1.b; // number | undefined
x1.c; // number
x1.d; // number
x2 = { a: 1 }; // Error
~~
!!! error TS2739: Type '{ a: number; }' is missing the following properties from type 'Required<Foo>': b, c, d
x2 = { a: 1, b: 1 }; // Error
~~
!!! error TS2739: Type '{ a: number; b: number; }' is missing the following properties from type 'Required<Foo>': c, d
x2 = { a: 1, b: 1, c: 1 }; // Error
~~
!!! error TS2741: Property 'd' is missing in type '{ a: number; b: number; c: number; }' but required in type 'Required<Foo>'.
!!! related TS2728 tests/cases/conformance/types/mapped/mappedTypes6.ts:82:5: 'd' is declared here.
x2 = { a: 1, b: 1, c: 1, d: 1 };
type Bar = {
a: number;
readonly b: number;
}
declare let x3: Bar;
x3.a = 1;
x3.b = 1; // Error
~
!!! error TS2540: Cannot assign to 'b' because it is a read-only property.
declare let x4: Readonly<Bar>;
x4.a = 1; // Error
~
!!! error TS2540: Cannot assign to 'a' because it is a read-only property.
x4.b = 1; // Error
~
!!! error TS2540: Cannot assign to 'b' because it is a read-only property.
declare let x5: Readwrite<Bar>;
x5.a = 1;
x5.b = 1;
|