1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
=== tests/cases/conformance/types/intersection/intersectionsAndEmptyObjects.ts ===
// Empty object type literals are removed from intersections types
// that contain other object types
type A = { a: number };
>A : A
>a : number
type B = { b: string };
>B : B
>b : string
type C = {};
>C : C
let x01: A & B;
>x01 : A & B
let x02: A & C;
>x02 : A
let x03: B & C;
>x03 : B
let x04: A & B & C;
>x04 : A & B
let x05: string & C;
>x05 : string & C
let x06: C & string;
>x06 : C & string
let x07: C;
>x07 : C
let x08: C & {};
>x08 : C
let x09: {} & A & {} & B & {} & C & {};
>x09 : A & B
interface D {}
interface E {}
let x10: A & D;
>x10 : A & D
let x11: C & D;
>x11 : D
let x12: A & B & C & D;
>x12 : A & B & D
let x13: D & E;
>x13 : D & E
let x14: A & B & C & D & E;
>x14 : A & B & D & E
// Repro from #20225
type Dictionary = { [name: string]: string };
>Dictionary : Dictionary
>name : string
const intersectDictionaries = <F1 extends Dictionary, F2 extends Dictionary>(
>intersectDictionaries : <F1 extends Dictionary, F2 extends Dictionary>(d1: F1, d2: F2) => F1 & F2
><F1 extends Dictionary, F2 extends Dictionary>( d1: F1, d2: F2,): F1 & F2 => Object.assign({}, d1, d2) : <F1 extends Dictionary, F2 extends Dictionary>(d1: F1, d2: F2) => F1 & F2
d1: F1,
>d1 : F1
d2: F2,
>d2 : F2
): F1 & F2 => Object.assign({}, d1, d2);
>Object.assign({}, d1, d2) : {} & F1 & F2
>Object.assign : { <T, U>(target: T, source: U): T & U; <T, U, V>(target: T, source1: U, source2: V): T & U & V; <T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W; (target: object, ...sources: any[]): any; }
>Object : ObjectConstructor
>assign : { <T, U>(target: T, source: U): T & U; <T, U, V>(target: T, source1: U, source2: V): T & U & V; <T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W; (target: object, ...sources: any[]): any; }
>{} : {}
>d1 : F1
>d2 : F2
const testDictionary = <T extends Dictionary>(_value: T) => { };
>testDictionary : <T extends Dictionary>(_value: T) => void
><T extends Dictionary>(_value: T) => { } : <T extends Dictionary>(_value: T) => void
>_value : T
const d1 = {};
>d1 : {}
>{} : {}
testDictionary(d1);
>testDictionary(d1) : void
>testDictionary : <T extends Dictionary>(_value: T) => void
>d1 : {}
const d2 = intersectDictionaries(d1, d1);
>d2 : {}
>intersectDictionaries(d1, d1) : {}
>intersectDictionaries : <F1 extends Dictionary, F2 extends Dictionary>(d1: F1, d2: F2) => F1 & F2
>d1 : {}
>d1 : {}
testDictionary(d2);
>testDictionary(d2) : void
>testDictionary : <T extends Dictionary>(_value: T) => void
>d2 : {}
const d3 = {
>d3 : { s: string; }
>{ s: '',} : { s: string; }
s: '',
>s : string
>'' : ""
};
testDictionary(d3);
>testDictionary(d3) : void
>testDictionary : <T extends Dictionary>(_value: T) => void
>d3 : { s: string; }
const d4 = intersectDictionaries(d1, d3);
>d4 : { s: string; }
>intersectDictionaries(d1, d3) : { s: string; }
>intersectDictionaries : <F1 extends Dictionary, F2 extends Dictionary>(d1: F1, d2: F2) => F1 & F2
>d1 : {}
>d3 : { s: string; }
testDictionary(d4);
>testDictionary(d4) : void
>testDictionary : <T extends Dictionary>(_value: T) => void
>d4 : { s: string; }
const d5 = intersectDictionaries(d3, d1);
>d5 : { s: string; }
>intersectDictionaries(d3, d1) : { s: string; }
>intersectDictionaries : <F1 extends Dictionary, F2 extends Dictionary>(d1: F1, d2: F2) => F1 & F2
>d3 : { s: string; }
>d1 : {}
testDictionary(d5);
>testDictionary(d5) : void
>testDictionary : <T extends Dictionary>(_value: T) => void
>d5 : { s: string; }
const d6 = intersectDictionaries(d3, d3);
>d6 : { s: string; }
>intersectDictionaries(d3, d3) : { s: string; }
>intersectDictionaries : <F1 extends Dictionary, F2 extends Dictionary>(d1: F1, d2: F2) => F1 & F2
>d3 : { s: string; }
>d3 : { s: string; }
testDictionary(d6);
>testDictionary(d6) : void
>testDictionary : <T extends Dictionary>(_value: T) => void
>d6 : { s: string; }
// Repro from #27044
type choices<IChoiceList extends {
>choices : choices<IChoiceList>
[key: string]: boolean;
>key : string
}> = IChoiceList & {
shoes:boolean;
>shoes : boolean
food:boolean;
>food : boolean
};
type IMyChoiceList = {
>IMyChoiceList : IMyChoiceList
car: true
>car : true
>true : true
};
type IUnknownChoiceList = {};
>IUnknownChoiceList : IUnknownChoiceList
var defaultChoices: choices<{}>;
>defaultChoices : { shoes: boolean; food: boolean; }
var defaultChoicesAndEmpty: choices<{} & {}>;
>defaultChoicesAndEmpty : { shoes: boolean; food: boolean; }
var myChoices: choices<IMyChoiceList>;
>myChoices : choices<IMyChoiceList>
var myChoicesAndEmpty: choices<IMyChoiceList & {}>;
>myChoicesAndEmpty : choices<IMyChoiceList>
var unknownChoices: choices<IUnknownChoiceList>;
>unknownChoices : { shoes: boolean; food: boolean; }
var unknownChoicesAndEmpty: choices<IUnknownChoiceList & {}>;
>unknownChoicesAndEmpty : { shoes: boolean; food: boolean; }
|