diff --git a/tests/baselines/reference/mappedTypes6.errors.txt b/tests/baselines/reference/mappedTypes6.errors.txt new file mode 100644 index 00000000000..843a59eecb5 --- /dev/null +++ b/tests/baselines/reference/mappedTypes6.errors.txt @@ -0,0 +1,195 @@ +tests/cases/conformance/types/mapped/mappedTypes6.ts(23,5): error TS2322: Type 'T' is not assignable to type 'Required'. +tests/cases/conformance/types/mapped/mappedTypes6.ts(24,5): error TS2322: Type 'Partial' is not assignable to type 'Required'. +tests/cases/conformance/types/mapped/mappedTypes6.ts(27,5): error TS2322: Type 'Partial' is not assignable to type 'T'. +tests/cases/conformance/types/mapped/mappedTypes6.ts(37,5): error TS2322: Type 'Required' is not assignable to type 'Denullified'. + Type 'T[P]' is not assignable to type 'NonNullable'. +tests/cases/conformance/types/mapped/mappedTypes6.ts(38,5): error TS2322: Type 'T' is not assignable to type 'Denullified'. +tests/cases/conformance/types/mapped/mappedTypes6.ts(39,5): error TS2322: Type 'Partial' is not assignable to type 'Denullified'. +tests/cases/conformance/types/mapped/mappedTypes6.ts(42,5): error TS2322: Type 'T' is not assignable to type 'Required'. +tests/cases/conformance/types/mapped/mappedTypes6.ts(43,5): error TS2322: Type 'Partial' is not assignable to type 'Required'. +tests/cases/conformance/types/mapped/mappedTypes6.ts(47,5): error TS2322: Type 'Partial' is not assignable to type 'T'. +tests/cases/conformance/types/mapped/mappedTypes6.ts(56,5): error TS2322: Type '{}' is not assignable to type 'Denullified'. +tests/cases/conformance/types/mapped/mappedTypes6.ts(57,5): error TS2322: Type '{}' is not assignable to type 'Required'. +tests/cases/conformance/types/mapped/mappedTypes6.ts(58,5): error TS2322: Type '{}' is not assignable to type 'T'. +tests/cases/conformance/types/mapped/mappedTypes6.ts(92,1): error TS2322: Type '{ a: number; }' is not assignable to type 'Foo'. + Property 'b' is missing in type '{ a: number; }'. +tests/cases/conformance/types/mapped/mappedTypes6.ts(104,1): error TS2322: Type '{ a: number; }' is not assignable to type 'Required'. + Property 'b' is missing in type '{ a: number; }'. +tests/cases/conformance/types/mapped/mappedTypes6.ts(105,1): error TS2322: Type '{ a: number; b: number; }' is not assignable to type 'Required'. + Property 'c' is missing in type '{ a: number; b: number; }'. +tests/cases/conformance/types/mapped/mappedTypes6.ts(106,1): error TS2322: Type '{ a: number; b: number; c: number; }' is not assignable to type 'Required'. + Property 'd' is missing in type '{ a: number; b: number; c: number; }'. +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. +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. +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. + + +==== tests/cases/conformance/types/mapped/mappedTypes6.ts (19 errors) ==== + type T00 = { [P in keyof T]: T[P] }; + type T01 = { [P in keyof T]?: T[P] }; + type T02 = { [P in keyof T]+?: T[P] }; + type T03 = { [P in keyof T]-?: T[P] }; + + type T04 = { readonly [P in keyof T]: T[P] }; + type T05 = { readonly [P in keyof T]?: T[P] }; + type T06 = { readonly [P in keyof T]+?: T[P] }; + type T07 = { readonly [P in keyof T]-?: T[P] }; + + type T08 = { +readonly [P in keyof T]: T[P] }; + type T09 = { +readonly [P in keyof T]?: T[P] }; + type T10 = { +readonly [P in keyof T]+?: T[P] }; + type T11 = { +readonly [P in keyof T]-?: T[P] }; + + type T12 = { -readonly [P in keyof T]: T[P] }; + type T13 = { -readonly [P in keyof T]?: T[P] }; + type T14 = { -readonly [P in keyof T]+?: T[P] }; + type T15 = { -readonly [P in keyof T]-?: T[P] }; + + function f1(x: Required, y: T, z: Partial) { + x = x; + x = y; // Error + ~ +!!! error TS2322: Type 'T' is not assignable to type 'Required'. + x = z; // Error + ~ +!!! error TS2322: Type 'Partial' is not assignable to type 'Required'. + y = x; + y = y; + y = z; // Error + ~ +!!! error TS2322: Type 'Partial' is not assignable to type 'T'. + z = x; + z = y; + z = z; + } + + type Denullified = { [P in keyof T]-?: NonNullable }; + + function f2(w: Denullified, x: Required, y: T, z: Partial) { + w = w; + w = x; // Error + ~ +!!! error TS2322: Type 'Required' is not assignable to type 'Denullified'. +!!! error TS2322: Type 'T[P]' is not assignable to type 'NonNullable'. + w = y; // Error + ~ +!!! error TS2322: Type 'T' is not assignable to type 'Denullified'. + w = z; // Error + ~ +!!! error TS2322: Type 'Partial' is not assignable to type 'Denullified'. + x = w; + x = x; + x = y; // Error + ~ +!!! error TS2322: Type 'T' is not assignable to type 'Required'. + x = z; // Error + ~ +!!! error TS2322: Type 'Partial' is not assignable to type 'Required'. + y = w; + y = x; + y = y; + y = z; // Error + ~ +!!! error TS2322: Type 'Partial' is not assignable to type 'T'. + z = w; + z = x; + z = y; + z = z; + } + + + function f3(w: Denullified, x: Required, y: T, z: Partial) { + w = {}; // Error + ~ +!!! error TS2322: Type '{}' is not assignable to type 'Denullified'. + x = {}; // Error + ~ +!!! error TS2322: Type '{}' is not assignable to type 'Required'. + y = {}; // Error + ~ +!!! error TS2322: Type '{}' is not assignable to type 'T'. + z = {}; + } + + type Readwrite = { + -readonly [P in keyof T]: T[P]; + } + + function f10(x: Readonly, y: T, z: Readwrite) { + 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 TS2322: Type '{ a: number; }' is not assignable to type 'Foo'. +!!! error TS2322: Property 'b' is missing in type '{ a: number; }'. + 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; + + x1.a; // number + x1.b; // number | undefined + x1.c; // number + x1.d; // number + + x2 = { a: 1 }; // Error + ~~ +!!! error TS2322: Type '{ a: number; }' is not assignable to type 'Required'. +!!! error TS2322: Property 'b' is missing in type '{ a: number; }'. + x2 = { a: 1, b: 1 }; // Error + ~~ +!!! error TS2322: Type '{ a: number; b: number; }' is not assignable to type 'Required'. +!!! error TS2322: Property 'c' is missing in type '{ a: number; b: number; }'. + x2 = { a: 1, b: 1, c: 1 }; // Error + ~~ +!!! error TS2322: Type '{ a: number; b: number; c: number; }' is not assignable to type 'Required'. +!!! error TS2322: Property 'd' is missing in type '{ a: number; b: number; c: number; }'. + 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 constant or a read-only property. + + declare let x4: Readonly; + x4.a = 1; // Error + ~ +!!! error TS2540: Cannot assign to 'a' because it is a constant or a read-only property. + x4.b = 1; // Error + ~ +!!! error TS2540: Cannot assign to 'b' because it is a constant or a read-only property. + + declare let x5: Readwrite; + x5.a = 1; + x5.b = 1; + \ No newline at end of file diff --git a/tests/baselines/reference/mappedTypes6.js b/tests/baselines/reference/mappedTypes6.js new file mode 100644 index 00000000000..b24d210eb75 --- /dev/null +++ b/tests/baselines/reference/mappedTypes6.js @@ -0,0 +1,273 @@ +//// [mappedTypes6.ts] +type T00 = { [P in keyof T]: T[P] }; +type T01 = { [P in keyof T]?: T[P] }; +type T02 = { [P in keyof T]+?: T[P] }; +type T03 = { [P in keyof T]-?: T[P] }; + +type T04 = { readonly [P in keyof T]: T[P] }; +type T05 = { readonly [P in keyof T]?: T[P] }; +type T06 = { readonly [P in keyof T]+?: T[P] }; +type T07 = { readonly [P in keyof T]-?: T[P] }; + +type T08 = { +readonly [P in keyof T]: T[P] }; +type T09 = { +readonly [P in keyof T]?: T[P] }; +type T10 = { +readonly [P in keyof T]+?: T[P] }; +type T11 = { +readonly [P in keyof T]-?: T[P] }; + +type T12 = { -readonly [P in keyof T]: T[P] }; +type T13 = { -readonly [P in keyof T]?: T[P] }; +type T14 = { -readonly [P in keyof T]+?: T[P] }; +type T15 = { -readonly [P in keyof T]-?: T[P] }; + +function f1(x: Required, y: T, z: Partial) { + x = x; + x = y; // Error + x = z; // Error + y = x; + y = y; + y = z; // Error + z = x; + z = y; + z = z; +} + +type Denullified = { [P in keyof T]-?: NonNullable }; + +function f2(w: Denullified, x: Required, y: T, z: Partial) { + w = w; + w = x; // Error + w = y; // Error + w = z; // Error + x = w; + x = x; + x = y; // Error + x = z; // Error + y = w; + y = x; + y = y; + y = z; // Error + z = w; + z = x; + z = y; + z = z; +} + + +function f3(w: Denullified, x: Required, y: T, z: Partial) { + w = {}; // Error + x = {}; // Error + y = {}; // Error + z = {}; +} + +type Readwrite = { + -readonly [P in keyof T]: T[P]; +} + +function f10(x: Readonly, y: T, z: Readwrite) { + 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 +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; + +x1.a; // number +x1.b; // number | undefined +x1.c; // number +x1.d; // number + +x2 = { a: 1 }; // Error +x2 = { a: 1, b: 1 }; // Error +x2 = { a: 1, b: 1, c: 1 }; // Error +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 + +declare let x4: Readonly; +x4.a = 1; // Error +x4.b = 1; // Error + +declare let x5: Readwrite; +x5.a = 1; +x5.b = 1; + + +//// [mappedTypes6.js] +"use strict"; +function f1(x, y, z) { + x = x; + x = y; // Error + x = z; // Error + y = x; + y = y; + y = z; // Error + z = x; + z = y; + z = z; +} +function f2(w, x, y, z) { + w = w; + w = x; // Error + w = y; // Error + w = z; // Error + x = w; + x = x; + x = y; // Error + x = z; // Error + y = w; + y = x; + y = y; + y = z; // Error + z = w; + z = x; + z = y; + z = z; +} +function f3(w, x, y, z) { + w = {}; // Error + x = {}; // Error + y = {}; // Error + z = {}; +} +function f10(x, y, z) { + x = x; + x = y; + x = z; + y = x; + y = y; + y = z; + z = x; + z = y; + z = z; +} +x1.a; // number +x1.b; // number | undefined +x1.c; // number | undefined +x1.d; // number | undefined +x1 = { a: 1 }; // Error +x1 = { a: 1, b: 1 }; +x1 = { a: 1, b: 1, c: 1 }; +x1 = { a: 1, b: 1, c: 1, d: 1 }; +x1.a; // number +x1.b; // number | undefined +x1.c; // number +x1.d; // number +x2 = { a: 1 }; // Error +x2 = { a: 1, b: 1 }; // Error +x2 = { a: 1, b: 1, c: 1 }; // Error +x2 = { a: 1, b: 1, c: 1, d: 1 }; +x3.a = 1; +x3.b = 1; // Error +x4.a = 1; // Error +x4.b = 1; // Error +x5.a = 1; +x5.b = 1; + + +//// [mappedTypes6.d.ts] +declare type T00 = { + [P in keyof T]: T[P]; +}; +declare type T01 = { + [P in keyof T]?: T[P]; +}; +declare type T02 = { + [P in keyof T]+?: T[P]; +}; +declare type T03 = { + [P in keyof T]-?: T[P]; +}; +declare type T04 = { + readonly [P in keyof T]: T[P]; +}; +declare type T05 = { + readonly [P in keyof T]?: T[P]; +}; +declare type T06 = { + readonly [P in keyof T]+?: T[P]; +}; +declare type T07 = { + readonly [P in keyof T]-?: T[P]; +}; +declare type T08 = { + +readonly [P in keyof T]: T[P]; +}; +declare type T09 = { + +readonly [P in keyof T]?: T[P]; +}; +declare type T10 = { + +readonly [P in keyof T]+?: T[P]; +}; +declare type T11 = { + +readonly [P in keyof T]-?: T[P]; +}; +declare type T12 = { + -readonly [P in keyof T]: T[P]; +}; +declare type T13 = { + -readonly [P in keyof T]?: T[P]; +}; +declare type T14 = { + -readonly [P in keyof T]+?: T[P]; +}; +declare type T15 = { + -readonly [P in keyof T]-?: T[P]; +}; +declare function f1(x: Required, y: T, z: Partial): void; +declare type Denullified = { + [P in keyof T]-?: NonNullable; +}; +declare function f2(w: Denullified, x: Required, y: T, z: Partial): void; +declare function f3(w: Denullified, x: Required, y: T, z: Partial): void; +declare type Readwrite = { + -readonly [P in keyof T]: T[P]; +}; +declare function f10(x: Readonly, y: T, z: Readwrite): void; +declare type Foo = { + a: number; + b: number | undefined; + c?: number; + d?: number | undefined; +}; +declare let x1: Foo; +declare let x2: Required; +declare type Bar = { + a: number; + readonly b: number; +}; +declare let x3: Bar; +declare let x4: Readonly; +declare let x5: Readwrite; diff --git a/tests/baselines/reference/mappedTypes6.symbols b/tests/baselines/reference/mappedTypes6.symbols new file mode 100644 index 00000000000..7cebcda184e --- /dev/null +++ b/tests/baselines/reference/mappedTypes6.symbols @@ -0,0 +1,519 @@ +=== tests/cases/conformance/types/mapped/mappedTypes6.ts === +type T00 = { [P in keyof T]: T[P] }; +>T00 : Symbol(T00, Decl(mappedTypes6.ts, 0, 0)) +>T : Symbol(T, Decl(mappedTypes6.ts, 0, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 0, 17)) +>T : Symbol(T, Decl(mappedTypes6.ts, 0, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 0, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 0, 17)) + +type T01 = { [P in keyof T]?: T[P] }; +>T01 : Symbol(T01, Decl(mappedTypes6.ts, 0, 39)) +>T : Symbol(T, Decl(mappedTypes6.ts, 1, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 1, 17)) +>T : Symbol(T, Decl(mappedTypes6.ts, 1, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 1, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 1, 17)) + +type T02 = { [P in keyof T]+?: T[P] }; +>T02 : Symbol(T02, Decl(mappedTypes6.ts, 1, 40)) +>T : Symbol(T, Decl(mappedTypes6.ts, 2, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 2, 17)) +>T : Symbol(T, Decl(mappedTypes6.ts, 2, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 2, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 2, 17)) + +type T03 = { [P in keyof T]-?: T[P] }; +>T03 : Symbol(T03, Decl(mappedTypes6.ts, 2, 41)) +>T : Symbol(T, Decl(mappedTypes6.ts, 3, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 3, 17)) +>T : Symbol(T, Decl(mappedTypes6.ts, 3, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 3, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 3, 17)) + +type T04 = { readonly [P in keyof T]: T[P] }; +>T04 : Symbol(T04, Decl(mappedTypes6.ts, 3, 41)) +>T : Symbol(T, Decl(mappedTypes6.ts, 5, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 5, 26)) +>T : Symbol(T, Decl(mappedTypes6.ts, 5, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 5, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 5, 26)) + +type T05 = { readonly [P in keyof T]?: T[P] }; +>T05 : Symbol(T05, Decl(mappedTypes6.ts, 5, 48)) +>T : Symbol(T, Decl(mappedTypes6.ts, 6, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 6, 26)) +>T : Symbol(T, Decl(mappedTypes6.ts, 6, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 6, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 6, 26)) + +type T06 = { readonly [P in keyof T]+?: T[P] }; +>T06 : Symbol(T06, Decl(mappedTypes6.ts, 6, 49)) +>T : Symbol(T, Decl(mappedTypes6.ts, 7, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 7, 26)) +>T : Symbol(T, Decl(mappedTypes6.ts, 7, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 7, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 7, 26)) + +type T07 = { readonly [P in keyof T]-?: T[P] }; +>T07 : Symbol(T07, Decl(mappedTypes6.ts, 7, 50)) +>T : Symbol(T, Decl(mappedTypes6.ts, 8, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 8, 26)) +>T : Symbol(T, Decl(mappedTypes6.ts, 8, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 8, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 8, 26)) + +type T08 = { +readonly [P in keyof T]: T[P] }; +>T08 : Symbol(T08, Decl(mappedTypes6.ts, 8, 50)) +>T : Symbol(T, Decl(mappedTypes6.ts, 10, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 10, 27)) +>T : Symbol(T, Decl(mappedTypes6.ts, 10, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 10, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 10, 27)) + +type T09 = { +readonly [P in keyof T]?: T[P] }; +>T09 : Symbol(T09, Decl(mappedTypes6.ts, 10, 49)) +>T : Symbol(T, Decl(mappedTypes6.ts, 11, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 11, 27)) +>T : Symbol(T, Decl(mappedTypes6.ts, 11, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 11, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 11, 27)) + +type T10 = { +readonly [P in keyof T]+?: T[P] }; +>T10 : Symbol(T10, Decl(mappedTypes6.ts, 11, 50)) +>T : Symbol(T, Decl(mappedTypes6.ts, 12, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 12, 27)) +>T : Symbol(T, Decl(mappedTypes6.ts, 12, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 12, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 12, 27)) + +type T11 = { +readonly [P in keyof T]-?: T[P] }; +>T11 : Symbol(T11, Decl(mappedTypes6.ts, 12, 51)) +>T : Symbol(T, Decl(mappedTypes6.ts, 13, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 13, 27)) +>T : Symbol(T, Decl(mappedTypes6.ts, 13, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 13, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 13, 27)) + +type T12 = { -readonly [P in keyof T]: T[P] }; +>T12 : Symbol(T12, Decl(mappedTypes6.ts, 13, 51)) +>T : Symbol(T, Decl(mappedTypes6.ts, 15, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 15, 27)) +>T : Symbol(T, Decl(mappedTypes6.ts, 15, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 15, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 15, 27)) + +type T13 = { -readonly [P in keyof T]?: T[P] }; +>T13 : Symbol(T13, Decl(mappedTypes6.ts, 15, 49)) +>T : Symbol(T, Decl(mappedTypes6.ts, 16, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 16, 27)) +>T : Symbol(T, Decl(mappedTypes6.ts, 16, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 16, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 16, 27)) + +type T14 = { -readonly [P in keyof T]+?: T[P] }; +>T14 : Symbol(T14, Decl(mappedTypes6.ts, 16, 50)) +>T : Symbol(T, Decl(mappedTypes6.ts, 17, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 17, 27)) +>T : Symbol(T, Decl(mappedTypes6.ts, 17, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 17, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 17, 27)) + +type T15 = { -readonly [P in keyof T]-?: T[P] }; +>T15 : Symbol(T15, Decl(mappedTypes6.ts, 17, 51)) +>T : Symbol(T, Decl(mappedTypes6.ts, 18, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 18, 27)) +>T : Symbol(T, Decl(mappedTypes6.ts, 18, 9)) +>T : Symbol(T, Decl(mappedTypes6.ts, 18, 9)) +>P : Symbol(P, Decl(mappedTypes6.ts, 18, 27)) + +function f1(x: Required, y: T, z: Partial) { +>f1 : Symbol(f1, Decl(mappedTypes6.ts, 18, 51)) +>T : Symbol(T, Decl(mappedTypes6.ts, 20, 12)) +>x : Symbol(x, Decl(mappedTypes6.ts, 20, 15)) +>Required : Symbol(Required, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypes6.ts, 20, 12)) +>y : Symbol(y, Decl(mappedTypes6.ts, 20, 30)) +>T : Symbol(T, Decl(mappedTypes6.ts, 20, 12)) +>z : Symbol(z, Decl(mappedTypes6.ts, 20, 36)) +>Partial : Symbol(Partial, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypes6.ts, 20, 12)) + + x = x; +>x : Symbol(x, Decl(mappedTypes6.ts, 20, 15)) +>x : Symbol(x, Decl(mappedTypes6.ts, 20, 15)) + + x = y; // Error +>x : Symbol(x, Decl(mappedTypes6.ts, 20, 15)) +>y : Symbol(y, Decl(mappedTypes6.ts, 20, 30)) + + x = z; // Error +>x : Symbol(x, Decl(mappedTypes6.ts, 20, 15)) +>z : Symbol(z, Decl(mappedTypes6.ts, 20, 36)) + + y = x; +>y : Symbol(y, Decl(mappedTypes6.ts, 20, 30)) +>x : Symbol(x, Decl(mappedTypes6.ts, 20, 15)) + + y = y; +>y : Symbol(y, Decl(mappedTypes6.ts, 20, 30)) +>y : Symbol(y, Decl(mappedTypes6.ts, 20, 30)) + + y = z; // Error +>y : Symbol(y, Decl(mappedTypes6.ts, 20, 30)) +>z : Symbol(z, Decl(mappedTypes6.ts, 20, 36)) + + z = x; +>z : Symbol(z, Decl(mappedTypes6.ts, 20, 36)) +>x : Symbol(x, Decl(mappedTypes6.ts, 20, 15)) + + z = y; +>z : Symbol(z, Decl(mappedTypes6.ts, 20, 36)) +>y : Symbol(y, Decl(mappedTypes6.ts, 20, 30)) + + z = z; +>z : Symbol(z, Decl(mappedTypes6.ts, 20, 36)) +>z : Symbol(z, Decl(mappedTypes6.ts, 20, 36)) +} + +type Denullified = { [P in keyof T]-?: NonNullable }; +>Denullified : Symbol(Denullified, Decl(mappedTypes6.ts, 30, 1)) +>T : Symbol(T, Decl(mappedTypes6.ts, 32, 17)) +>P : Symbol(P, Decl(mappedTypes6.ts, 32, 25)) +>T : Symbol(T, Decl(mappedTypes6.ts, 32, 17)) +>NonNullable : Symbol(NonNullable, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypes6.ts, 32, 17)) +>P : Symbol(P, Decl(mappedTypes6.ts, 32, 25)) + +function f2(w: Denullified, x: Required, y: T, z: Partial) { +>f2 : Symbol(f2, Decl(mappedTypes6.ts, 32, 62)) +>T : Symbol(T, Decl(mappedTypes6.ts, 34, 12)) +>w : Symbol(w, Decl(mappedTypes6.ts, 34, 15)) +>Denullified : Symbol(Denullified, Decl(mappedTypes6.ts, 30, 1)) +>T : Symbol(T, Decl(mappedTypes6.ts, 34, 12)) +>x : Symbol(x, Decl(mappedTypes6.ts, 34, 33)) +>Required : Symbol(Required, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypes6.ts, 34, 12)) +>y : Symbol(y, Decl(mappedTypes6.ts, 34, 49)) +>T : Symbol(T, Decl(mappedTypes6.ts, 34, 12)) +>z : Symbol(z, Decl(mappedTypes6.ts, 34, 55)) +>Partial : Symbol(Partial, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypes6.ts, 34, 12)) + + w = w; +>w : Symbol(w, Decl(mappedTypes6.ts, 34, 15)) +>w : Symbol(w, Decl(mappedTypes6.ts, 34, 15)) + + w = x; // Error +>w : Symbol(w, Decl(mappedTypes6.ts, 34, 15)) +>x : Symbol(x, Decl(mappedTypes6.ts, 34, 33)) + + w = y; // Error +>w : Symbol(w, Decl(mappedTypes6.ts, 34, 15)) +>y : Symbol(y, Decl(mappedTypes6.ts, 34, 49)) + + w = z; // Error +>w : Symbol(w, Decl(mappedTypes6.ts, 34, 15)) +>z : Symbol(z, Decl(mappedTypes6.ts, 34, 55)) + + x = w; +>x : Symbol(x, Decl(mappedTypes6.ts, 34, 33)) +>w : Symbol(w, Decl(mappedTypes6.ts, 34, 15)) + + x = x; +>x : Symbol(x, Decl(mappedTypes6.ts, 34, 33)) +>x : Symbol(x, Decl(mappedTypes6.ts, 34, 33)) + + x = y; // Error +>x : Symbol(x, Decl(mappedTypes6.ts, 34, 33)) +>y : Symbol(y, Decl(mappedTypes6.ts, 34, 49)) + + x = z; // Error +>x : Symbol(x, Decl(mappedTypes6.ts, 34, 33)) +>z : Symbol(z, Decl(mappedTypes6.ts, 34, 55)) + + y = w; +>y : Symbol(y, Decl(mappedTypes6.ts, 34, 49)) +>w : Symbol(w, Decl(mappedTypes6.ts, 34, 15)) + + y = x; +>y : Symbol(y, Decl(mappedTypes6.ts, 34, 49)) +>x : Symbol(x, Decl(mappedTypes6.ts, 34, 33)) + + y = y; +>y : Symbol(y, Decl(mappedTypes6.ts, 34, 49)) +>y : Symbol(y, Decl(mappedTypes6.ts, 34, 49)) + + y = z; // Error +>y : Symbol(y, Decl(mappedTypes6.ts, 34, 49)) +>z : Symbol(z, Decl(mappedTypes6.ts, 34, 55)) + + z = w; +>z : Symbol(z, Decl(mappedTypes6.ts, 34, 55)) +>w : Symbol(w, Decl(mappedTypes6.ts, 34, 15)) + + z = x; +>z : Symbol(z, Decl(mappedTypes6.ts, 34, 55)) +>x : Symbol(x, Decl(mappedTypes6.ts, 34, 33)) + + z = y; +>z : Symbol(z, Decl(mappedTypes6.ts, 34, 55)) +>y : Symbol(y, Decl(mappedTypes6.ts, 34, 49)) + + z = z; +>z : Symbol(z, Decl(mappedTypes6.ts, 34, 55)) +>z : Symbol(z, Decl(mappedTypes6.ts, 34, 55)) +} + + +function f3(w: Denullified, x: Required, y: T, z: Partial) { +>f3 : Symbol(f3, Decl(mappedTypes6.ts, 51, 1)) +>T : Symbol(T, Decl(mappedTypes6.ts, 54, 12)) +>w : Symbol(w, Decl(mappedTypes6.ts, 54, 15)) +>Denullified : Symbol(Denullified, Decl(mappedTypes6.ts, 30, 1)) +>T : Symbol(T, Decl(mappedTypes6.ts, 54, 12)) +>x : Symbol(x, Decl(mappedTypes6.ts, 54, 33)) +>Required : Symbol(Required, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypes6.ts, 54, 12)) +>y : Symbol(y, Decl(mappedTypes6.ts, 54, 49)) +>T : Symbol(T, Decl(mappedTypes6.ts, 54, 12)) +>z : Symbol(z, Decl(mappedTypes6.ts, 54, 55)) +>Partial : Symbol(Partial, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypes6.ts, 54, 12)) + + w = {}; // Error +>w : Symbol(w, Decl(mappedTypes6.ts, 54, 15)) + + x = {}; // Error +>x : Symbol(x, Decl(mappedTypes6.ts, 54, 33)) + + y = {}; // Error +>y : Symbol(y, Decl(mappedTypes6.ts, 54, 49)) + + z = {}; +>z : Symbol(z, Decl(mappedTypes6.ts, 54, 55)) +} + +type Readwrite = { +>Readwrite : Symbol(Readwrite, Decl(mappedTypes6.ts, 59, 1)) +>T : Symbol(T, Decl(mappedTypes6.ts, 61, 15)) + + -readonly [P in keyof T]: T[P]; +>P : Symbol(P, Decl(mappedTypes6.ts, 62, 15)) +>T : Symbol(T, Decl(mappedTypes6.ts, 61, 15)) +>T : Symbol(T, Decl(mappedTypes6.ts, 61, 15)) +>P : Symbol(P, Decl(mappedTypes6.ts, 62, 15)) +} + +function f10(x: Readonly, y: T, z: Readwrite) { +>f10 : Symbol(f10, Decl(mappedTypes6.ts, 63, 1)) +>T : Symbol(T, Decl(mappedTypes6.ts, 65, 13)) +>x : Symbol(x, Decl(mappedTypes6.ts, 65, 16)) +>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --)) +>T : Symbol(T, Decl(mappedTypes6.ts, 65, 13)) +>y : Symbol(y, Decl(mappedTypes6.ts, 65, 31)) +>T : Symbol(T, Decl(mappedTypes6.ts, 65, 13)) +>z : Symbol(z, Decl(mappedTypes6.ts, 65, 37)) +>Readwrite : Symbol(Readwrite, Decl(mappedTypes6.ts, 59, 1)) +>T : Symbol(T, Decl(mappedTypes6.ts, 65, 13)) + + x = x; +>x : Symbol(x, Decl(mappedTypes6.ts, 65, 16)) +>x : Symbol(x, Decl(mappedTypes6.ts, 65, 16)) + + x = y; +>x : Symbol(x, Decl(mappedTypes6.ts, 65, 16)) +>y : Symbol(y, Decl(mappedTypes6.ts, 65, 31)) + + x = z; +>x : Symbol(x, Decl(mappedTypes6.ts, 65, 16)) +>z : Symbol(z, Decl(mappedTypes6.ts, 65, 37)) + + y = x; +>y : Symbol(y, Decl(mappedTypes6.ts, 65, 31)) +>x : Symbol(x, Decl(mappedTypes6.ts, 65, 16)) + + y = y; +>y : Symbol(y, Decl(mappedTypes6.ts, 65, 31)) +>y : Symbol(y, Decl(mappedTypes6.ts, 65, 31)) + + y = z; +>y : Symbol(y, Decl(mappedTypes6.ts, 65, 31)) +>z : Symbol(z, Decl(mappedTypes6.ts, 65, 37)) + + z = x; +>z : Symbol(z, Decl(mappedTypes6.ts, 65, 37)) +>x : Symbol(x, Decl(mappedTypes6.ts, 65, 16)) + + z = y; +>z : Symbol(z, Decl(mappedTypes6.ts, 65, 37)) +>y : Symbol(y, Decl(mappedTypes6.ts, 65, 31)) + + z = z; +>z : Symbol(z, Decl(mappedTypes6.ts, 65, 37)) +>z : Symbol(z, Decl(mappedTypes6.ts, 65, 37)) +} + +type Foo = { +>Foo : Symbol(Foo, Decl(mappedTypes6.ts, 75, 1)) + + a: number; +>a : Symbol(a, Decl(mappedTypes6.ts, 77, 12)) + + b: number | undefined; +>b : Symbol(b, Decl(mappedTypes6.ts, 78, 14)) + + c?: number; +>c : Symbol(c, Decl(mappedTypes6.ts, 79, 26)) + + d?: number | undefined; +>d : Symbol(d, Decl(mappedTypes6.ts, 80, 15)) +} + +declare let x1: Foo; +>x1 : Symbol(x1, Decl(mappedTypes6.ts, 84, 11)) +>Foo : Symbol(Foo, Decl(mappedTypes6.ts, 75, 1)) + +x1.a; // number +>x1.a : Symbol(a, Decl(mappedTypes6.ts, 77, 12)) +>x1 : Symbol(x1, Decl(mappedTypes6.ts, 84, 11)) +>a : Symbol(a, Decl(mappedTypes6.ts, 77, 12)) + +x1.b; // number | undefined +>x1.b : Symbol(b, Decl(mappedTypes6.ts, 78, 14)) +>x1 : Symbol(x1, Decl(mappedTypes6.ts, 84, 11)) +>b : Symbol(b, Decl(mappedTypes6.ts, 78, 14)) + +x1.c; // number | undefined +>x1.c : Symbol(c, Decl(mappedTypes6.ts, 79, 26)) +>x1 : Symbol(x1, Decl(mappedTypes6.ts, 84, 11)) +>c : Symbol(c, Decl(mappedTypes6.ts, 79, 26)) + +x1.d; // number | undefined +>x1.d : Symbol(d, Decl(mappedTypes6.ts, 80, 15)) +>x1 : Symbol(x1, Decl(mappedTypes6.ts, 84, 11)) +>d : Symbol(d, Decl(mappedTypes6.ts, 80, 15)) + +x1 = { a: 1 }; // Error +>x1 : Symbol(x1, Decl(mappedTypes6.ts, 84, 11)) +>a : Symbol(a, Decl(mappedTypes6.ts, 91, 6)) + +x1 = { a: 1, b: 1 }; +>x1 : Symbol(x1, Decl(mappedTypes6.ts, 84, 11)) +>a : Symbol(a, Decl(mappedTypes6.ts, 92, 6)) +>b : Symbol(b, Decl(mappedTypes6.ts, 92, 12)) + +x1 = { a: 1, b: 1, c: 1 }; +>x1 : Symbol(x1, Decl(mappedTypes6.ts, 84, 11)) +>a : Symbol(a, Decl(mappedTypes6.ts, 93, 6)) +>b : Symbol(b, Decl(mappedTypes6.ts, 93, 12)) +>c : Symbol(c, Decl(mappedTypes6.ts, 93, 18)) + +x1 = { a: 1, b: 1, c: 1, d: 1 }; +>x1 : Symbol(x1, Decl(mappedTypes6.ts, 84, 11)) +>a : Symbol(a, Decl(mappedTypes6.ts, 94, 6)) +>b : Symbol(b, Decl(mappedTypes6.ts, 94, 12)) +>c : Symbol(c, Decl(mappedTypes6.ts, 94, 18)) +>d : Symbol(d, Decl(mappedTypes6.ts, 94, 24)) + +declare let x2: Required; +>x2 : Symbol(x2, Decl(mappedTypes6.ts, 96, 11)) +>Required : Symbol(Required, Decl(lib.d.ts, --, --)) +>Foo : Symbol(Foo, Decl(mappedTypes6.ts, 75, 1)) + +x1.a; // number +>x1.a : Symbol(a, Decl(mappedTypes6.ts, 77, 12)) +>x1 : Symbol(x1, Decl(mappedTypes6.ts, 84, 11)) +>a : Symbol(a, Decl(mappedTypes6.ts, 77, 12)) + +x1.b; // number | undefined +>x1.b : Symbol(b, Decl(mappedTypes6.ts, 78, 14)) +>x1 : Symbol(x1, Decl(mappedTypes6.ts, 84, 11)) +>b : Symbol(b, Decl(mappedTypes6.ts, 78, 14)) + +x1.c; // number +>x1.c : Symbol(c, Decl(mappedTypes6.ts, 79, 26)) +>x1 : Symbol(x1, Decl(mappedTypes6.ts, 84, 11)) +>c : Symbol(c, Decl(mappedTypes6.ts, 79, 26)) + +x1.d; // number +>x1.d : Symbol(d, Decl(mappedTypes6.ts, 80, 15)) +>x1 : Symbol(x1, Decl(mappedTypes6.ts, 84, 11)) +>d : Symbol(d, Decl(mappedTypes6.ts, 80, 15)) + +x2 = { a: 1 }; // Error +>x2 : Symbol(x2, Decl(mappedTypes6.ts, 96, 11)) +>a : Symbol(a, Decl(mappedTypes6.ts, 103, 6)) + +x2 = { a: 1, b: 1 }; // Error +>x2 : Symbol(x2, Decl(mappedTypes6.ts, 96, 11)) +>a : Symbol(a, Decl(mappedTypes6.ts, 104, 6)) +>b : Symbol(b, Decl(mappedTypes6.ts, 104, 12)) + +x2 = { a: 1, b: 1, c: 1 }; // Error +>x2 : Symbol(x2, Decl(mappedTypes6.ts, 96, 11)) +>a : Symbol(a, Decl(mappedTypes6.ts, 105, 6)) +>b : Symbol(b, Decl(mappedTypes6.ts, 105, 12)) +>c : Symbol(c, Decl(mappedTypes6.ts, 105, 18)) + +x2 = { a: 1, b: 1, c: 1, d: 1 }; +>x2 : Symbol(x2, Decl(mappedTypes6.ts, 96, 11)) +>a : Symbol(a, Decl(mappedTypes6.ts, 106, 6)) +>b : Symbol(b, Decl(mappedTypes6.ts, 106, 12)) +>c : Symbol(c, Decl(mappedTypes6.ts, 106, 18)) +>d : Symbol(d, Decl(mappedTypes6.ts, 106, 24)) + +type Bar = { +>Bar : Symbol(Bar, Decl(mappedTypes6.ts, 106, 32)) + + a: number; +>a : Symbol(a, Decl(mappedTypes6.ts, 108, 12)) + + readonly b: number; +>b : Symbol(b, Decl(mappedTypes6.ts, 109, 14)) +} + +declare let x3: Bar; +>x3 : Symbol(x3, Decl(mappedTypes6.ts, 113, 11)) +>Bar : Symbol(Bar, Decl(mappedTypes6.ts, 106, 32)) + +x3.a = 1; +>x3.a : Symbol(a, Decl(mappedTypes6.ts, 108, 12)) +>x3 : Symbol(x3, Decl(mappedTypes6.ts, 113, 11)) +>a : Symbol(a, Decl(mappedTypes6.ts, 108, 12)) + +x3.b = 1; // Error +>x3.b : Symbol(b, Decl(mappedTypes6.ts, 109, 14)) +>x3 : Symbol(x3, Decl(mappedTypes6.ts, 113, 11)) +>b : Symbol(b, Decl(mappedTypes6.ts, 109, 14)) + +declare let x4: Readonly; +>x4 : Symbol(x4, Decl(mappedTypes6.ts, 117, 11)) +>Readonly : Symbol(Readonly, Decl(lib.d.ts, --, --)) +>Bar : Symbol(Bar, Decl(mappedTypes6.ts, 106, 32)) + +x4.a = 1; // Error +>x4.a : Symbol(a, Decl(mappedTypes6.ts, 108, 12)) +>x4 : Symbol(x4, Decl(mappedTypes6.ts, 117, 11)) +>a : Symbol(a, Decl(mappedTypes6.ts, 108, 12)) + +x4.b = 1; // Error +>x4.b : Symbol(b, Decl(mappedTypes6.ts, 109, 14)) +>x4 : Symbol(x4, Decl(mappedTypes6.ts, 117, 11)) +>b : Symbol(b, Decl(mappedTypes6.ts, 109, 14)) + +declare let x5: Readwrite; +>x5 : Symbol(x5, Decl(mappedTypes6.ts, 121, 11)) +>Readwrite : Symbol(Readwrite, Decl(mappedTypes6.ts, 59, 1)) +>Bar : Symbol(Bar, Decl(mappedTypes6.ts, 106, 32)) + +x5.a = 1; +>x5.a : Symbol(a, Decl(mappedTypes6.ts, 108, 12)) +>x5 : Symbol(x5, Decl(mappedTypes6.ts, 121, 11)) +>a : Symbol(a, Decl(mappedTypes6.ts, 108, 12)) + +x5.b = 1; +>x5.b : Symbol(b, Decl(mappedTypes6.ts, 109, 14)) +>x5 : Symbol(x5, Decl(mappedTypes6.ts, 121, 11)) +>b : Symbol(b, Decl(mappedTypes6.ts, 109, 14)) + diff --git a/tests/baselines/reference/mappedTypes6.types b/tests/baselines/reference/mappedTypes6.types new file mode 100644 index 00000000000..5b554d53fe7 --- /dev/null +++ b/tests/baselines/reference/mappedTypes6.types @@ -0,0 +1,609 @@ +=== tests/cases/conformance/types/mapped/mappedTypes6.ts === +type T00 = { [P in keyof T]: T[P] }; +>T00 : T00 +>T : T +>P : P +>T : T +>T : T +>P : P + +type T01 = { [P in keyof T]?: T[P] }; +>T01 : T01 +>T : T +>P : P +>T : T +>T : T +>P : P + +type T02 = { [P in keyof T]+?: T[P] }; +>T02 : T02 +>T : T +>P : P +>T : T +>T : T +>P : P + +type T03 = { [P in keyof T]-?: T[P] }; +>T03 : T03 +>T : T +>P : P +>T : T +>T : T +>P : P + +type T04 = { readonly [P in keyof T]: T[P] }; +>T04 : T04 +>T : T +>P : P +>T : T +>T : T +>P : P + +type T05 = { readonly [P in keyof T]?: T[P] }; +>T05 : T05 +>T : T +>P : P +>T : T +>T : T +>P : P + +type T06 = { readonly [P in keyof T]+?: T[P] }; +>T06 : T06 +>T : T +>P : P +>T : T +>T : T +>P : P + +type T07 = { readonly [P in keyof T]-?: T[P] }; +>T07 : T07 +>T : T +>P : P +>T : T +>T : T +>P : P + +type T08 = { +readonly [P in keyof T]: T[P] }; +>T08 : T08 +>T : T +>P : P +>T : T +>T : T +>P : P + +type T09 = { +readonly [P in keyof T]?: T[P] }; +>T09 : T09 +>T : T +>P : P +>T : T +>T : T +>P : P + +type T10 = { +readonly [P in keyof T]+?: T[P] }; +>T10 : T10 +>T : T +>P : P +>T : T +>T : T +>P : P + +type T11 = { +readonly [P in keyof T]-?: T[P] }; +>T11 : T11 +>T : T +>P : P +>T : T +>T : T +>P : P + +type T12 = { -readonly [P in keyof T]: T[P] }; +>T12 : T12 +>T : T +>P : P +>T : T +>T : T +>P : P + +type T13 = { -readonly [P in keyof T]?: T[P] }; +>T13 : T13 +>T : T +>P : P +>T : T +>T : T +>P : P + +type T14 = { -readonly [P in keyof T]+?: T[P] }; +>T14 : T14 +>T : T +>P : P +>T : T +>T : T +>P : P + +type T15 = { -readonly [P in keyof T]-?: T[P] }; +>T15 : T15 +>T : T +>P : P +>T : T +>T : T +>P : P + +function f1(x: Required, y: T, z: Partial) { +>f1 : (x: Required, y: T, z: Partial) => void +>T : T +>x : Required +>Required : Required +>T : T +>y : T +>T : T +>z : Partial +>Partial : Partial +>T : T + + x = x; +>x = x : Required +>x : Required +>x : Required + + x = y; // Error +>x = y : T +>x : Required +>y : T + + x = z; // Error +>x = z : Partial +>x : Required +>z : Partial + + y = x; +>y = x : Required +>y : T +>x : Required + + y = y; +>y = y : T +>y : T +>y : T + + y = z; // Error +>y = z : Partial +>y : T +>z : Partial + + z = x; +>z = x : Required +>z : Partial +>x : Required + + z = y; +>z = y : T +>z : Partial +>y : T + + z = z; +>z = z : Partial +>z : Partial +>z : Partial +} + +type Denullified = { [P in keyof T]-?: NonNullable }; +>Denullified : Denullified +>T : T +>P : P +>T : T +>NonNullable : NonNullable +>T : T +>P : P + +function f2(w: Denullified, x: Required, y: T, z: Partial) { +>f2 : (w: Denullified, x: Required, y: T, z: Partial) => void +>T : T +>w : Denullified +>Denullified : Denullified +>T : T +>x : Required +>Required : Required +>T : T +>y : T +>T : T +>z : Partial +>Partial : Partial +>T : T + + w = w; +>w = w : Denullified +>w : Denullified +>w : Denullified + + w = x; // Error +>w = x : Required +>w : Denullified +>x : Required + + w = y; // Error +>w = y : T +>w : Denullified +>y : T + + w = z; // Error +>w = z : Partial +>w : Denullified +>z : Partial + + x = w; +>x = w : Denullified +>x : Required +>w : Denullified + + x = x; +>x = x : Required +>x : Required +>x : Required + + x = y; // Error +>x = y : T +>x : Required +>y : T + + x = z; // Error +>x = z : Partial +>x : Required +>z : Partial + + y = w; +>y = w : Denullified +>y : T +>w : Denullified + + y = x; +>y = x : Required +>y : T +>x : Required + + y = y; +>y = y : T +>y : T +>y : T + + y = z; // Error +>y = z : Partial +>y : T +>z : Partial + + z = w; +>z = w : Denullified +>z : Partial +>w : Denullified + + z = x; +>z = x : Required +>z : Partial +>x : Required + + z = y; +>z = y : T +>z : Partial +>y : T + + z = z; +>z = z : Partial +>z : Partial +>z : Partial +} + + +function f3(w: Denullified, x: Required, y: T, z: Partial) { +>f3 : (w: Denullified, x: Required, y: T, z: Partial) => void +>T : T +>w : Denullified +>Denullified : Denullified +>T : T +>x : Required +>Required : Required +>T : T +>y : T +>T : T +>z : Partial +>Partial : Partial +>T : T + + w = {}; // Error +>w = {} : {} +>w : Denullified +>{} : {} + + x = {}; // Error +>x = {} : {} +>x : Required +>{} : {} + + y = {}; // Error +>y = {} : {} +>y : T +>{} : {} + + z = {}; +>z = {} : {} +>z : Partial +>{} : {} +} + +type Readwrite = { +>Readwrite : Readwrite +>T : T + + -readonly [P in keyof T]: T[P]; +>P : P +>T : T +>T : T +>P : P +} + +function f10(x: Readonly, y: T, z: Readwrite) { +>f10 : (x: Readonly, y: T, z: Readwrite) => void +>T : T +>x : Readonly +>Readonly : Readonly +>T : T +>y : T +>T : T +>z : Readwrite +>Readwrite : Readwrite +>T : T + + x = x; +>x = x : Readonly +>x : Readonly +>x : Readonly + + x = y; +>x = y : T +>x : Readonly +>y : T + + x = z; +>x = z : Readwrite +>x : Readonly +>z : Readwrite + + y = x; +>y = x : Readonly +>y : T +>x : Readonly + + y = y; +>y = y : T +>y : T +>y : T + + y = z; +>y = z : Readwrite +>y : T +>z : Readwrite + + z = x; +>z = x : Readonly +>z : Readwrite +>x : Readonly + + z = y; +>z = y : T +>z : Readwrite +>y : T + + z = z; +>z = z : Readwrite +>z : Readwrite +>z : Readwrite +} + +type Foo = { +>Foo : Foo + + a: number; +>a : number + + b: number | undefined; +>b : number | undefined + + c?: number; +>c : number | undefined + + d?: number | undefined; +>d : number | undefined +} + +declare let x1: Foo; +>x1 : Foo +>Foo : Foo + +x1.a; // number +>x1.a : number +>x1 : Foo +>a : number + +x1.b; // number | undefined +>x1.b : number | undefined +>x1 : Foo +>b : number | undefined + +x1.c; // number | undefined +>x1.c : number | undefined +>x1 : Foo +>c : number | undefined + +x1.d; // number | undefined +>x1.d : number | undefined +>x1 : Foo +>d : number | undefined + +x1 = { a: 1 }; // Error +>x1 = { a: 1 } : { a: number; } +>x1 : Foo +>{ a: 1 } : { a: number; } +>a : number +>1 : 1 + +x1 = { a: 1, b: 1 }; +>x1 = { a: 1, b: 1 } : { a: number; b: number; } +>x1 : Foo +>{ a: 1, b: 1 } : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>1 : 1 + +x1 = { a: 1, b: 1, c: 1 }; +>x1 = { a: 1, b: 1, c: 1 } : { a: number; b: number; c: number; } +>x1 : Foo +>{ a: 1, b: 1, c: 1 } : { a: number; b: number; c: number; } +>a : number +>1 : 1 +>b : number +>1 : 1 +>c : number +>1 : 1 + +x1 = { a: 1, b: 1, c: 1, d: 1 }; +>x1 = { a: 1, b: 1, c: 1, d: 1 } : { a: number; b: number; c: number; d: number; } +>x1 : Foo +>{ a: 1, b: 1, c: 1, d: 1 } : { a: number; b: number; c: number; d: number; } +>a : number +>1 : 1 +>b : number +>1 : 1 +>c : number +>1 : 1 +>d : number +>1 : 1 + +declare let x2: Required; +>x2 : Required +>Required : Required +>Foo : Foo + +x1.a; // number +>x1.a : number +>x1 : Foo +>a : number + +x1.b; // number | undefined +>x1.b : number | undefined +>x1 : Foo +>b : number | undefined + +x1.c; // number +>x1.c : number | undefined +>x1 : Foo +>c : number | undefined + +x1.d; // number +>x1.d : number | undefined +>x1 : Foo +>d : number | undefined + +x2 = { a: 1 }; // Error +>x2 = { a: 1 } : { a: number; } +>x2 : Required +>{ a: 1 } : { a: number; } +>a : number +>1 : 1 + +x2 = { a: 1, b: 1 }; // Error +>x2 = { a: 1, b: 1 } : { a: number; b: number; } +>x2 : Required +>{ a: 1, b: 1 } : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>1 : 1 + +x2 = { a: 1, b: 1, c: 1 }; // Error +>x2 = { a: 1, b: 1, c: 1 } : { a: number; b: number; c: number; } +>x2 : Required +>{ a: 1, b: 1, c: 1 } : { a: number; b: number; c: number; } +>a : number +>1 : 1 +>b : number +>1 : 1 +>c : number +>1 : 1 + +x2 = { a: 1, b: 1, c: 1, d: 1 }; +>x2 = { a: 1, b: 1, c: 1, d: 1 } : { a: number; b: number; c: number; d: number; } +>x2 : Required +>{ a: 1, b: 1, c: 1, d: 1 } : { a: number; b: number; c: number; d: number; } +>a : number +>1 : 1 +>b : number +>1 : 1 +>c : number +>1 : 1 +>d : number +>1 : 1 + +type Bar = { +>Bar : Bar + + a: number; +>a : number + + readonly b: number; +>b : number +} + +declare let x3: Bar; +>x3 : Bar +>Bar : Bar + +x3.a = 1; +>x3.a = 1 : 1 +>x3.a : number +>x3 : Bar +>a : number +>1 : 1 + +x3.b = 1; // Error +>x3.b = 1 : 1 +>x3.b : any +>x3 : Bar +>b : any +>1 : 1 + +declare let x4: Readonly; +>x4 : Readonly +>Readonly : Readonly +>Bar : Bar + +x4.a = 1; // Error +>x4.a = 1 : 1 +>x4.a : any +>x4 : Readonly +>a : any +>1 : 1 + +x4.b = 1; // Error +>x4.b = 1 : 1 +>x4.b : any +>x4 : Readonly +>b : any +>1 : 1 + +declare let x5: Readwrite; +>x5 : Readwrite +>Readwrite : Readwrite +>Bar : Bar + +x5.a = 1; +>x5.a = 1 : 1 +>x5.a : number +>x5 : Readwrite +>a : number +>1 : 1 + +x5.b = 1; +>x5.b = 1 : 1 +>x5.b : number +>x5 : Readwrite +>b : number +>1 : 1 +