File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
tests/cases/conformance/types/intersection Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ // @target : es2015
2
+
1
3
// Empty object type literals are removed from intersections types
2
4
// that contain other object types
3
5
@@ -23,3 +25,54 @@ let x11: C & D;
23
25
let x12 : A & B & C & D ;
24
26
let x13 : D & E ;
25
27
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 & { } > ;
You can’t perform that action at this time.
0 commit comments