Skip to content

Commit 6ae775b

Browse files
committed
Support intersection types as target in type inference
1 parent c517a63 commit 6ae775b

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5408,11 +5408,11 @@ namespace ts {
54085408
inferFromTypes(sourceTypes[i], targetTypes[i]);
54095409
}
54105410
}
5411-
else if (target.flags & TypeFlags.Union) {
5412-
let targetTypes = (<UnionType>target).types;
5411+
else if (target.flags & TypeFlags.UnionOrIntersection) {
5412+
let targetTypes = (<UnionOrIntersectionType>target).types;
54135413
let typeParameterCount = 0;
54145414
let typeParameter: TypeParameter;
5415-
// First infer to each type in union that isn't a type parameter
5415+
// First infer to each type in union or intersection that isn't a type parameter
54165416
for (let t of targetTypes) {
54175417
if (t.flags & TypeFlags.TypeParameter && contains(context.typeParameters, t)) {
54185418
typeParameter = <TypeParameter>t;
@@ -5422,8 +5422,9 @@ namespace ts {
54225422
inferFromTypes(source, t);
54235423
}
54245424
}
5425-
// If union contains a single naked type parameter, make a secondary inference to that type parameter
5426-
if (typeParameterCount === 1) {
5425+
// Next, if target is a union type containing a single naked type parameter, make a
5426+
// secondary inference to that type parameter
5427+
if (target.flags & TypeFlags.Union && typeParameterCount === 1) {
54275428
inferiority++;
54285429
inferFromTypes(source, typeParameter);
54295430
inferiority--;

0 commit comments

Comments
 (0)