narrow type for generic variables inside TypeQuery (#48434)

This commit is contained in:
Zzzen
2022-04-06 00:33:19 +08:00
committed by GitHub
parent 25aecd4c3e
commit 370d34cdca
6 changed files with 222 additions and 0 deletions

View File

@@ -25311,6 +25311,7 @@ namespace ts {
// a generic type without a nullable constraint and x is a generic type. This is because when both obj
// and x are of generic types T and K, we want the resulting type to be T[K].
return parent.kind === SyntaxKind.PropertyAccessExpression ||
parent.kind === SyntaxKind.QualifiedName ||
parent.kind === SyntaxKind.CallExpression && (parent as CallExpression).expression === node ||
parent.kind === SyntaxKind.ElementAccessExpression && (parent as ElementAccessExpression).expression === node &&
!(someType(type, isGenericTypeWithoutNullableConstraint) && isGenericIndexType(getTypeOfExpression((parent as ElementAccessExpression).argumentExpression)));