Skip to content

Commit 78fd6d9

Browse files
committed
add an extra test case
1 parent 6732851 commit 78fd6d9

5 files changed

+127
-1
lines changed

tests/baselines/reference/elementWiseErrorInUnionTarget3.errors.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ elementWiseErrorInUnionTarget3.ts(44,5): error TS2322: Type 'number' is not assi
44
elementWiseErrorInUnionTarget3.ts(61,5): error TS2322: Type 'number' is not assignable to type 'string'.
55
elementWiseErrorInUnionTarget3.ts(73,5): error TS2322: Type 'number' is not assignable to type 'string'.
66
elementWiseErrorInUnionTarget3.ts(90,5): error TS2322: Type 'boolean' is not assignable to type 'string'.
7+
elementWiseErrorInUnionTarget3.ts(107,5): error TS2322: Type 'number' is not assignable to type 'string'.
78

89

9-
==== elementWiseErrorInUnionTarget3.ts (6 errors) ====
10+
==== elementWiseErrorInUnionTarget3.ts (7 errors) ====
1011
const obj1: {
1112
prop:
1213
| string
@@ -116,4 +117,24 @@ elementWiseErrorInUnionTarget3.ts(90,5): error TS2322: Type 'boolean' is not ass
116117
!!! related TS6500 elementWiseErrorInUnionTarget3.ts:81:9: The expected type comes from property 'prop' which is declared here on type '{ type: "foo"; prop: string; } | { type: "bar"; prop: number; }'
117118
},
118119
};
120+
121+
const obj7: {
122+
prop:
123+
| {
124+
type: "foo";
125+
prop: string;
126+
}
127+
| {
128+
type: "bar";
129+
prop: number;
130+
};
131+
} = {
132+
prop: {
133+
type: "foo",
134+
prop: 42,
135+
~~~~
136+
!!! error TS2322: Type 'number' is not assignable to type 'string'.
137+
!!! related TS6500 elementWiseErrorInUnionTarget3.ts:98:9: The expected type comes from property 'prop' which is declared here on type '{ type: "foo"; prop: string; } | { type: "bar"; prop: number; }'
138+
},
139+
};
119140

tests/baselines/reference/elementWiseErrorInUnionTarget3.symbols

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,37 @@ const obj6: {
182182
},
183183
};
184184

185+
const obj7: {
186+
>obj7 : Symbol(obj7, Decl(elementWiseErrorInUnionTarget3.ts, 93, 5))
187+
188+
prop:
189+
>prop : Symbol(prop, Decl(elementWiseErrorInUnionTarget3.ts, 93, 13))
190+
191+
| {
192+
type: "foo";
193+
>type : Symbol(type, Decl(elementWiseErrorInUnionTarget3.ts, 95, 7))
194+
195+
prop: string;
196+
>prop : Symbol(prop, Decl(elementWiseErrorInUnionTarget3.ts, 96, 20))
197+
}
198+
| {
199+
type: "bar";
200+
>type : Symbol(type, Decl(elementWiseErrorInUnionTarget3.ts, 99, 7))
201+
202+
prop: number;
203+
>prop : Symbol(prop, Decl(elementWiseErrorInUnionTarget3.ts, 100, 20))
204+
205+
};
206+
} = {
207+
prop: {
208+
>prop : Symbol(prop, Decl(elementWiseErrorInUnionTarget3.ts, 103, 5))
209+
210+
type: "foo",
211+
>type : Symbol(type, Decl(elementWiseErrorInUnionTarget3.ts, 104, 9))
212+
213+
prop: 42,
214+
>prop : Symbol(prop, Decl(elementWiseErrorInUnionTarget3.ts, 105, 16))
215+
216+
},
217+
};
218+

tests/baselines/reference/elementWiseErrorInUnionTarget3.types

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,42 @@ const obj6: {
204204
},
205205
};
206206

207+
const obj7: {
208+
>obj7 : { prop: { type: "foo"; prop: string;} | { type: "bar"; prop: number;}; }
209+
210+
prop:
211+
>prop : { type: "foo"; prop: string; } | { type: "bar"; prop: number; }
212+
213+
| {
214+
type: "foo";
215+
>type : "foo"
216+
217+
prop: string;
218+
>prop : string
219+
}
220+
| {
221+
type: "bar";
222+
>type : "bar"
223+
224+
prop: number;
225+
>prop : number
226+
227+
};
228+
} = {
229+
>{ prop: { type: "foo", prop: 42, },} : { prop: { type: "foo"; prop: number; }; }
230+
231+
prop: {
232+
>prop : { type: "foo"; prop: number; }
233+
>{ type: "foo", prop: 42, } : { type: "foo"; prop: number; }
234+
235+
type: "foo",
236+
>type : "foo"
237+
>"foo" : "foo"
238+
239+
prop: 42,
240+
>prop : number
241+
>42 : 42
242+
243+
},
244+
};
245+

tests/cases/compiler/elementWiseErrorInUnionTarget3.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,20 @@ const obj6: {
9494
prop: true,
9595
},
9696
};
97+
98+
const obj7: {
99+
prop:
100+
| {
101+
type: "foo";
102+
prop: string;
103+
}
104+
| {
105+
type: "bar";
106+
prop: number;
107+
};
108+
} = {
109+
prop: {
110+
type: "foo",
111+
prop: 42,
112+
},
113+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
//// // https://github.com/microsoft/TypeScript/issues/57540
4+
////
5+
//// const foo = { b: 100 };
6+
////
7+
//// const bar: {
8+
//// a: number;
9+
//// b: number;
10+
//// } = {
11+
//// a: 42,
12+
//// .../*1*/
13+
//// };
14+
15+
verify.completions({ marker: "1", includes: ["foo"], excludes: ["b"] });

0 commit comments

Comments
 (0)