Fix iterable contextual type (#40592)

This commit is contained in:
Andrew Branch
2020-09-17 10:42:47 -07:00
committed by GitHub
parent d779a19053
commit 735a67a05e
5 changed files with 105 additions and 1 deletions

View File

@@ -23651,7 +23651,10 @@ namespace ts {
function getContextualTypeForElementExpression(arrayContextualType: Type | undefined, index: number): Type | undefined {
return arrayContextualType && (
getTypeOfPropertyOfContextualType(arrayContextualType, "" + index as __String)
|| getIteratedTypeOrElementType(IterationUse.Element, arrayContextualType, undefinedType, /*errorNode*/ undefined, /*checkAssignability*/ false));
|| mapType(
arrayContextualType,
t => getIteratedTypeOrElementType(IterationUse.Element, t, undefinedType, /*errorNode*/ undefined, /*checkAssignability*/ false),
/*noReductions*/ true));
}
// In a contextually typed conditional expression, the true/false expressions are contextually typed by the same type.