diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8ef7b3453a2..a69751673f6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15516,6 +15516,10 @@ namespace ts { } } else if (target.flags & TypeFlags.Intersection && some((target).types, t => !!getInferenceInfoForType(t))) { + // We reduce intersection types only when they contain naked type parameters. For example, when + // inferring from 'string[] & { extra: any }' to 'string[] & T' we want to remove string[] and + // infer { extra: any } for T. But when inferring to 'string[] & Iterable' we want to keep the + // string[] on the source side and infer string for T. if (source.flags & TypeFlags.Intersection) { // Infer between identically matching source and target constituents and remove the matching types. const [sources, targets] = inferFromMatchingTypes((source).types, (target).types, isTypeIdenticalTo);