Skip to content

Commit d37484e

Browse files
committed
Perform structural inference for type parameters that are awaited
1 parent cecab84 commit d37484e

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/compiler/checker.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18218,10 +18218,10 @@ namespace ts {
1821818218
propagationType = savePropagationType;
1821918219
return;
1822018220
}
18221-
if (source.aliasSymbol && source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol) {
18221+
if (source.aliasSymbol && source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol &&
18222+
inferFromTypeArguments(source.aliasTypeArguments, target.aliasTypeArguments!, getAliasVariances(source.aliasSymbol))) {
1822218223
// Source and target are types originating in the same generic type alias declaration.
1822318224
// Simply infer from source type arguments to target type arguments.
18224-
inferFromTypeArguments(source.aliasTypeArguments, target.aliasTypeArguments!, getAliasVariances(source.aliasSymbol));
1822518225
return;
1822618226
}
1822718227
if (source === target && source.flags & TypeFlags.UnionOrIntersection) {
@@ -18341,9 +18341,9 @@ namespace ts {
1834118341
}
1834218342
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (
1834318343
(<TypeReference>source).target === (<TypeReference>target).target || isArrayType(source) && isArrayType(target)) &&
18344-
!((<TypeReference>source).node && (<TypeReference>target).node)) {
18344+
!((<TypeReference>source).node && (<TypeReference>target).node) &&
18345+
inferFromTypeArguments(getTypeArguments(<TypeReference>source), getTypeArguments(<TypeReference>target), getVariances((<TypeReference>source).target))) {
1834518346
// If source and target are references to the same generic type, infer from type arguments
18346-
inferFromTypeArguments(getTypeArguments(<TypeReference>source), getTypeArguments(<TypeReference>target), getVariances((<TypeReference>source).target));
1834718347
}
1834818348
else if (source.flags & TypeFlags.Index && target.flags & TypeFlags.Index) {
1834918349
contravariant = !contravariant;
@@ -18463,6 +18463,9 @@ namespace ts {
1846318463
}
1846418464

1846518465
function inferFromTypeArguments(sourceTypes: readonly Type[], targetTypes: readonly Type[], variances: readonly VarianceFlags[]) {
18466+
if (some(variances, variance => !!(variance & VarianceFlags.Awaited))) {
18467+
return false;
18468+
}
1846618469
const count = sourceTypes.length < targetTypes.length ? sourceTypes.length : targetTypes.length;
1846718470
for (let i = 0; i < count; i++) {
1846818471
if (i < variances.length && (variances[i] & VarianceFlags.VarianceMask) === VarianceFlags.Contravariant) {
@@ -18475,6 +18478,7 @@ namespace ts {
1847518478
inferFromTypes(sourceTypes[i], targetTypes[i]);
1847618479
}
1847718480
}
18481+
return true;
1847818482
}
1847918483

1848018484
function inferFromContravariantTypes(source: Type, target: Type) {
@@ -18680,9 +18684,9 @@ namespace ts {
1868018684

1868118685
function inferFromObjectTypesWorker(source: Type, target: Type) {
1868218686
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (
18683-
(<TypeReference>source).target === (<TypeReference>target).target || isArrayType(source) && isArrayType(target))) {
18687+
(<TypeReference>source).target === (<TypeReference>target).target || isArrayType(source) && isArrayType(target)) &&
18688+
inferFromTypeArguments(getTypeArguments(<TypeReference>source), getTypeArguments(<TypeReference>target), getVariances((<TypeReference>source).target))) {
1868418689
// If source and target are references to the same generic type, infer from type arguments
18685-
inferFromTypeArguments(getTypeArguments(<TypeReference>source), getTypeArguments(<TypeReference>target), getVariances((<TypeReference>source).target));
1868618690
return;
1868718691
}
1868818692
if (isGenericMappedType(source) && isGenericMappedType(target)) {

0 commit comments

Comments
 (0)