@@ -14724,17 +14724,25 @@ namespace ts {
14724
14724
inferFromTypes(source, (<ConditionalType>target).falseType);
14725
14725
}
14726
14726
else if (target.flags & TypeFlags.UnionOrIntersection) {
14727
+ // We infer from types that are not naked type variables first so that inferences we
14728
+ // make from nested naked type variables and given slightly higher priority by virtue
14729
+ // of being first in the candidates array.
14730
+ for (const t of (<UnionOrIntersectionType>target).types) {
14731
+ if (!getInferenceInfoForType(t)) {
14732
+ inferFromTypes(source, t);
14733
+ }
14734
+ }
14735
+ // Inferences directly to naked type variables are given lower priority as they are
14736
+ // less specific. For example, when inferring from Promise<string> to T | Promise<T>,
14737
+ // we want to infer string for T, not Promise<string> | string.
14738
+ const savePriority = priority;
14739
+ priority |= InferencePriority.NakedTypeVariable;
14727
14740
for (const t of (<UnionOrIntersectionType>target).types) {
14728
- const savePriority = priority;
14729
- // Inferences directly to naked type variables are given lower priority as they are
14730
- // less specific. For example, when inferring from Promise<string> to T | Promise<T>,
14731
- // we want to infer string for T, not Promise<string> | string.
14732
14741
if (getInferenceInfoForType(t)) {
14733
- priority |= InferencePriority.NakedTypeVariable ;
14742
+ inferFromTypes(source, t) ;
14734
14743
}
14735
- inferFromTypes(source, t);
14736
- priority = savePriority;
14737
14744
}
14745
+ priority = savePriority;
14738
14746
}
14739
14747
else if (source.flags & TypeFlags.Union) {
14740
14748
// Source is a union or intersection type, infer from each constituent type
0 commit comments