Skip to content

Commit a3b8ad2

Browse files
Accepted baselines.
1 parent 96095ef commit a3b8ad2

4 files changed

+163
-24
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
tests/cases/compiler/contextualTypeShouldBeLiteral.ts(40,5): error TS2345: Argument of type '{ type2: "y"; value: "done"; method(): void; }' is not assignable to parameter of type 'X2 | Y2'.
2+
Object literal may only specify known properties, but 'type2' does not exist in type 'X2'. Did you mean to write 'type1'?
3+
4+
5+
==== tests/cases/compiler/contextualTypeShouldBeLiteral.ts (1 errors) ====
6+
interface X {
7+
type: 'x';
8+
value: string;
9+
method(): void;
10+
}
11+
12+
interface Y {
13+
type: 'y';
14+
value: 'none' | 'done';
15+
method(): void;
16+
}
17+
18+
function foo(bar: X | Y) { }
19+
20+
foo({
21+
type: 'y',
22+
value: 'done',
23+
method() {
24+
this;
25+
this.type;
26+
this.value;
27+
}
28+
});
29+
30+
interface X2 {
31+
type1: 'x';
32+
value: string;
33+
method(): void;
34+
}
35+
36+
interface Y2 {
37+
type2: 'y';
38+
value: 'none' | 'done';
39+
method(): void;
40+
}
41+
42+
function foo2(bar: X2 | Y2) { }
43+
44+
foo2({
45+
type2: 'y',
46+
~~~~~~~~~~
47+
!!! error TS2345: Argument of type '{ type2: "y"; value: "done"; method(): void; }' is not assignable to parameter of type 'X2 | Y2'.
48+
!!! error TS2345: Object literal may only specify known properties, but 'type2' does not exist in type 'X2'. Did you mean to write 'type1'?
49+
value: 'done',
50+
method() {
51+
this;
52+
this.value;
53+
}
54+
});
55+
56+
interface X3 {
57+
type: 'x';
58+
value: 1 | 2 | 3;
59+
xtra: number;
60+
}
61+
62+
interface Y3 {
63+
type: 'y';
64+
value: 11 | 12 | 13;
65+
ytra: number;
66+
}
67+
68+
let xy: X3 | Y3 = {
69+
type: 'y',
70+
value: 11,
71+
ytra: 12
72+
};
73+
74+
xy;
75+
76+
77+
interface LikeA {
78+
x: 'x';
79+
y: 'y';
80+
value: string;
81+
method(): void;
82+
}
83+
84+
interface LikeB {
85+
x: 'xx';
86+
y: 'yy';
87+
value: number;
88+
method(): void;
89+
}
90+
91+
let xyz: LikeA | LikeB = {
92+
x: 'x',
93+
y: 'y',
94+
value: "foo",
95+
method() {
96+
this;
97+
this.x;
98+
this.y;
99+
this.value;
100+
}
101+
};
102+
103+
xyz;
104+
105+
// Repro from #29168
106+
107+
interface TestObject {
108+
type?: 'object';
109+
items: {
110+
[k: string]: TestGeneric;
111+
};
112+
}
113+
114+
interface TestString {
115+
type: 'string';
116+
}
117+
118+
type TestGeneric = (TestString | TestObject) & { [k: string]: any; };
119+
120+
const test: TestGeneric = {
121+
items: {
122+
hello: { type: 'string' },
123+
world: {
124+
items: {
125+
nested: { type: 'string' }
126+
}
127+
}
128+
}
129+
};
130+

tests/baselines/reference/excessPropertyCheckWithMultipleDiscriminants.errors.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ tests/cases/compiler/excessPropertyCheckWithMultipleDiscriminants.ts(30,5): erro
22
Object literal may only specify known properties, and 'multipleOf' does not exist in type 'Float'.
33
tests/cases/compiler/excessPropertyCheckWithMultipleDiscriminants.ts(41,5): error TS2322: Type '{ p1: "left"; p2: false; p3: number; p4: string; }' is not assignable to type 'DisjointDiscriminants'.
44
Object literal may only specify known properties, and 'p3' does not exist in type '{ p1: "left"; p2: boolean; }'.
5+
tests/cases/compiler/excessPropertyCheckWithMultipleDiscriminants.ts(50,5): error TS2322: Type '{ p1: "left"; p2: true; p3: number; p4: string; }' is not assignable to type 'DisjointDiscriminants'.
6+
Object literal may only specify known properties, and 'p4' does not exist in type '{ p1: "left"; p2: true; p3: number; }'.
57
tests/cases/compiler/excessPropertyCheckWithMultipleDiscriminants.ts(57,5): error TS2322: Type '{ p1: "right"; p2: false; p3: number; p4: string; }' is not assignable to type 'DisjointDiscriminants'.
68
Object literal may only specify known properties, and 'p3' does not exist in type '{ p1: "right"; p2: false; p4: string; }'.
79

810

9-
==== tests/cases/compiler/excessPropertyCheckWithMultipleDiscriminants.ts (3 errors) ====
11+
==== tests/cases/compiler/excessPropertyCheckWithMultipleDiscriminants.ts (4 errors) ====
1012
// Repro from #32657
1113

1214
interface Base<T> {
@@ -63,6 +65,9 @@ tests/cases/compiler/excessPropertyCheckWithMultipleDiscriminants.ts(57,5): erro
6365
p2: true,
6466
p3: 42,
6567
p4: "hello"
68+
~~~~~~~~~~~
69+
!!! error TS2322: Type '{ p1: "left"; p2: true; p3: number; p4: string; }' is not assignable to type 'DisjointDiscriminants'.
70+
!!! error TS2322: Object literal may only specify known properties, and 'p4' does not exist in type '{ p1: "left"; p2: true; p3: number; }'.
6671
};
6772

6873
// This has excess error because variant two is the only applicable case

tests/baselines/reference/excessPropertyCheckWithUnions.errors.txt

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ tests/cases/compiler/excessPropertyCheckWithUnions.ts(11,21): error TS2322: Type
44
Object literal may only specify known properties, and 'd20' does not exist in type '{ tag: "A"; a1: string; }'.
55
tests/cases/compiler/excessPropertyCheckWithUnions.ts(12,1): error TS2322: Type '{ tag: "D"; }' is not assignable to type 'ADT'.
66
Property 'd20' is missing in type '{ tag: "D"; }' but required in type '{ tag: "D"; d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20; }'.
7+
tests/cases/compiler/excessPropertyCheckWithUnions.ts(29,19): error TS2322: Type '{ tag: "A"; y: number; }' is not assignable to type 'Ambiguous'.
8+
Object literal may only specify known properties, and 'y' does not exist in type '{ tag: "A"; x: string; }'.
9+
tests/cases/compiler/excessPropertyCheckWithUnions.ts(30,28): error TS2322: Type '{ tag: "A"; x: string; y: number; }' is not assignable to type 'Ambiguous'.
10+
Object literal may only specify known properties, and 'y' does not exist in type '{ tag: "A"; x: string; }'.
711
tests/cases/compiler/excessPropertyCheckWithUnions.ts(33,28): error TS2322: Type '{ tag: "A"; x: string; extra: number; }' is not assignable to type 'Ambiguous'.
8-
Object literal may only specify known properties, and 'extra' does not exist in type 'Ambiguous'.
9-
tests/cases/compiler/excessPropertyCheckWithUnions.ts(34,26): error TS2322: Type '{ tag: "A"; y: number; extra: number; }' is not assignable to type 'Ambiguous'.
10-
Object literal may only specify known properties, and 'extra' does not exist in type 'Ambiguous'.
12+
Object literal may only specify known properties, and 'extra' does not exist in type '{ tag: "A"; x: string; }'.
13+
tests/cases/compiler/excessPropertyCheckWithUnions.ts(34,19): error TS2322: Type '{ tag: "A"; y: number; extra: number; }' is not assignable to type 'Ambiguous'.
14+
Object literal may only specify known properties, and 'y' does not exist in type '{ tag: "A"; x: string; }'.
1115
tests/cases/compiler/excessPropertyCheckWithUnions.ts(39,1): error TS2322: Type '{ tag: "A"; }' is not assignable to type 'Ambiguous'.
12-
Type '{ tag: "A"; }' is not assignable to type '{ tag: "C"; }'.
13-
Types of property 'tag' are incompatible.
14-
Type '"A"' is not assignable to type '"C"'.
15-
tests/cases/compiler/excessPropertyCheckWithUnions.ts(40,1): error TS2322: Type '{ tag: "A"; z: true; }' is not assignable to type 'Ambiguous'.
16-
Type '{ tag: "A"; z: true; }' is not assignable to type '{ tag: "B"; z: boolean; }'.
17-
Types of property 'tag' are incompatible.
18-
Type '"A"' is not assignable to type '"B"'.
16+
Property 'x' is missing in type '{ tag: "A"; }' but required in type '{ tag: "A"; x: string; }'.
17+
tests/cases/compiler/excessPropertyCheckWithUnions.ts(40,19): error TS2322: Type '{ tag: "A"; z: true; }' is not assignable to type 'Ambiguous'.
18+
Object literal may only specify known properties, and 'z' does not exist in type '{ tag: "A"; x: string; }'.
1919
tests/cases/compiler/excessPropertyCheckWithUnions.ts(49,35): error TS2322: Type '{ a: 1; b: 1; first: string; second: string; }' is not assignable to type 'Overlapping'.
2020
Object literal may only specify known properties, and 'second' does not exist in type '{ a: 1; b: 1; first: string; }'.
2121
tests/cases/compiler/excessPropertyCheckWithUnions.ts(50,35): error TS2322: Type '{ a: 1; b: 1; first: string; third: string; }' is not assignable to type 'Overlapping'.
@@ -31,7 +31,7 @@ tests/cases/compiler/excessPropertyCheckWithUnions.ts(113,67): error TS2322: Typ
3131
tests/cases/compiler/excessPropertyCheckWithUnions.ts(114,63): error TS2322: Type 'string' is not assignable to type 'number'.
3232

3333

34-
==== tests/cases/compiler/excessPropertyCheckWithUnions.ts (14 errors) ====
34+
==== tests/cases/compiler/excessPropertyCheckWithUnions.ts (16 errors) ====
3535
type ADT = {
3636
tag: "A",
3737
a1: string
@@ -71,33 +71,36 @@ tests/cases/compiler/excessPropertyCheckWithUnions.ts(114,63): error TS2322: Typ
7171
// no error for ambiguous tag, even when it could satisfy both constituents at once
7272
amb = { tag: "A", x: "hi" }
7373
amb = { tag: "A", y: 12 }
74+
~~~~~
75+
!!! error TS2322: Type '{ tag: "A"; y: number; }' is not assignable to type 'Ambiguous'.
76+
!!! error TS2322: Object literal may only specify known properties, and 'y' does not exist in type '{ tag: "A"; x: string; }'.
7477
amb = { tag: "A", x: "hi", y: 12 }
78+
~~~~~
79+
!!! error TS2322: Type '{ tag: "A"; x: string; y: number; }' is not assignable to type 'Ambiguous'.
80+
!!! error TS2322: Object literal may only specify known properties, and 'y' does not exist in type '{ tag: "A"; x: string; }'.
7581

7682
// correctly error on excess property 'extra', even when ambiguous
7783
amb = { tag: "A", x: "hi", extra: 12 }
7884
~~~~~~~~~
7985
!!! error TS2322: Type '{ tag: "A"; x: string; extra: number; }' is not assignable to type 'Ambiguous'.
80-
!!! error TS2322: Object literal may only specify known properties, and 'extra' does not exist in type 'Ambiguous'.
86+
!!! error TS2322: Object literal may only specify known properties, and 'extra' does not exist in type '{ tag: "A"; x: string; }'.
8187
amb = { tag: "A", y: 12, extra: 12 }
82-
~~~~~~~~~
88+
~~~~~
8389
!!! error TS2322: Type '{ tag: "A"; y: number; extra: number; }' is not assignable to type 'Ambiguous'.
84-
!!! error TS2322: Object literal may only specify known properties, and 'extra' does not exist in type 'Ambiguous'.
90+
!!! error TS2322: Object literal may only specify known properties, and 'y' does not exist in type '{ tag: "A"; x: string; }'.
8591

8692
// assignability errors still work.
8793
// But note that the error for `z: true` is the fallback one of reporting on
8894
// the last constituent since assignability error reporting can't find a single best discriminant either.
8995
amb = { tag: "A" }
9096
~~~
9197
!!! error TS2322: Type '{ tag: "A"; }' is not assignable to type 'Ambiguous'.
92-
!!! error TS2322: Type '{ tag: "A"; }' is not assignable to type '{ tag: "C"; }'.
93-
!!! error TS2322: Types of property 'tag' are incompatible.
94-
!!! error TS2322: Type '"A"' is not assignable to type '"C"'.
98+
!!! error TS2322: Property 'x' is missing in type '{ tag: "A"; }' but required in type '{ tag: "A"; x: string; }'.
99+
!!! related TS2728 tests/cases/compiler/excessPropertyCheckWithUnions.ts:16:5: 'x' is declared here.
95100
amb = { tag: "A", z: true }
96-
~~~
101+
~~~~~~~
97102
!!! error TS2322: Type '{ tag: "A"; z: true; }' is not assignable to type 'Ambiguous'.
98-
!!! error TS2322: Type '{ tag: "A"; z: true; }' is not assignable to type '{ tag: "B"; z: boolean; }'.
99-
!!! error TS2322: Types of property 'tag' are incompatible.
100-
!!! error TS2322: Type '"A"' is not assignable to type '"B"'.
103+
!!! error TS2322: Object literal may only specify known properties, and 'z' does not exist in type '{ tag: "A"; x: string; }'.
101104

102105
type Overlapping =
103106
| { a: 1, b: 1, first: string }

tests/baselines/reference/objectLiteralNormalization.errors.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
tests/cases/conformance/expressions/objectLiterals/objectLiteralNormalization.ts(7,14): error TS2322: Type 'number' is not assignable to type 'string | undefined'.
22
tests/cases/conformance/expressions/objectLiterals/objectLiteralNormalization.ts(8,1): error TS2322: Type '{ b: string; }' is not assignable to type '{ a: number; b?: undefined; c?: undefined; } | { a: number; b: string; c?: undefined; } | { a: number; b: string; c: boolean; }'.
3-
Type '{ b: string; }' is missing the following properties from type '{ a: number; b: string; c: boolean; }': a, c
3+
Property 'a' is missing in type '{ b: string; }' but required in type '{ a: number; b: string; c?: undefined; }'.
44
tests/cases/conformance/expressions/objectLiterals/objectLiteralNormalization.ts(9,1): error TS2322: Type '{ c: true; }' is not assignable to type '{ a: number; b?: undefined; c?: undefined; } | { a: number; b: string; c?: undefined; } | { a: number; b: string; c: boolean; }'.
55
Type '{ c: true; }' is missing the following properties from type '{ a: number; b: string; c: boolean; }': a, b
66
tests/cases/conformance/expressions/objectLiterals/objectLiteralNormalization.ts(17,1): error TS2322: Type '{ a: string; b: number; }' is not assignable to type '{ a: number; b: number; } | { a: string; b?: undefined; } | { a?: undefined; b?: undefined; }'.
@@ -27,7 +27,8 @@ tests/cases/conformance/expressions/objectLiterals/objectLiteralNormalization.ts
2727
a1 = { b: "y" }; // Error
2828
~~
2929
!!! error TS2322: Type '{ b: string; }' is not assignable to type '{ a: number; b?: undefined; c?: undefined; } | { a: number; b: string; c?: undefined; } | { a: number; b: string; c: boolean; }'.
30-
!!! error TS2322: Type '{ b: string; }' is missing the following properties from type '{ a: number; b: string; c: boolean; }': a, c
30+
!!! error TS2322: Property 'a' is missing in type '{ b: string; }' but required in type '{ a: number; b: string; c?: undefined; }'.
31+
!!! related TS2728 tests/cases/conformance/expressions/objectLiterals/objectLiteralNormalization.ts:2:23: 'a' is declared here.
3132
a1 = { c: true }; // Error
3233
~~
3334
!!! error TS2322: Type '{ c: true; }' is not assignable to type '{ a: number; b?: undefined; c?: undefined; } | { a: number; b: string; c?: undefined; } | { a: number; b: string; c: boolean; }'.

0 commit comments

Comments
 (0)