@@ -14773,22 +14773,29 @@ namespace ts {
14773
14773
// We infer from types that are not naked type variables first so that inferences we
14774
14774
// make from nested naked type variables and given slightly higher priority by virtue
14775
14775
// of being first in the candidates array.
14776
+ let typeVariableCount = 0;
14776
14777
for (const t of (<UnionOrIntersectionType>target).types) {
14777
- if (!getInferenceInfoForType(t)) {
14778
+ if (getInferenceInfoForType(t)) {
14779
+ typeVariableCount++;
14780
+ }
14781
+ else {
14778
14782
inferFromTypes(source, t);
14779
14783
}
14780
14784
}
14781
14785
// Inferences directly to naked type variables are given lower priority as they are
14782
14786
// less specific. For example, when inferring from Promise<string> to T | Promise<T>,
14783
- // we want to infer string for T, not Promise<string> | string.
14784
- const savePriority = priority;
14785
- priority |= InferencePriority.NakedTypeVariable;
14786
- for (const t of (<UnionOrIntersectionType>target).types) {
14787
- if (getInferenceInfoForType(t)) {
14788
- inferFromTypes(source, t);
14787
+ // we want to infer string for T, not Promise<string> | string. For intersection types
14788
+ // we only infer to single naked type variables.
14789
+ if (target.flags & TypeFlags.Union ? typeVariableCount !== 0 : typeVariableCount === 1) {
14790
+ const savePriority = priority;
14791
+ priority |= InferencePriority.NakedTypeVariable;
14792
+ for (const t of (<UnionOrIntersectionType>target).types) {
14793
+ if (getInferenceInfoForType(t)) {
14794
+ inferFromTypes(source, t);
14795
+ }
14789
14796
}
14797
+ priority = savePriority;
14790
14798
}
14791
- priority = savePriority;
14792
14799
}
14793
14800
else if (source.flags & TypeFlags.Union) {
14794
14801
// Source is a union or intersection type, infer from each constituent type
0 commit comments