Skip to content

Commit 627f1ad

Browse files
committed
Add regression tests
1 parent e95ed29 commit 627f1ad

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @target: es2015
2+
13
// Empty object type literals are removed from intersections types
24
// that contain other object types
35

@@ -23,3 +25,54 @@ let x11: C & D;
2325
let x12: A & B & C & D;
2426
let x13: D & E;
2527
let x14: A & B & C & D & E;
28+
29+
// Repro from #20225
30+
31+
type Dictionary = { [name: string]: string };
32+
33+
const intersectDictionaries = <F1 extends Dictionary, F2 extends Dictionary>(
34+
d1: F1,
35+
d2: F2,
36+
): F1 & F2 => Object.assign({}, d1, d2);
37+
38+
const testDictionary = <T extends Dictionary>(_value: T) => { };
39+
40+
const d1 = {};
41+
testDictionary(d1);
42+
const d2 = intersectDictionaries(d1, d1);
43+
testDictionary(d2);
44+
45+
const d3 = {
46+
s: '',
47+
};
48+
testDictionary(d3);
49+
const d4 = intersectDictionaries(d1, d3);
50+
testDictionary(d4);
51+
const d5 = intersectDictionaries(d3, d1);
52+
testDictionary(d5);
53+
const d6 = intersectDictionaries(d3, d3);
54+
testDictionary(d6);
55+
56+
// Repro from #27044
57+
58+
type choices<IChoiceList extends {
59+
[key: string]: boolean;
60+
}> = IChoiceList & {
61+
shoes:boolean;
62+
food:boolean;
63+
};
64+
65+
type IMyChoiceList = {
66+
car: true
67+
};
68+
69+
type IUnknownChoiceList = {};
70+
71+
var defaultChoices: choices<{}>;
72+
var defaultChoicesAndEmpty: choices<{} & {}>;
73+
74+
var myChoices: choices<IMyChoiceList>;
75+
var myChoicesAndEmpty: choices<IMyChoiceList & {}>;
76+
77+
var unknownChoices: choices<IUnknownChoiceList>;
78+
var unknownChoicesAndEmpty: choices<IUnknownChoiceList & {}>;

0 commit comments

Comments
 (0)