Skip to content

Commit 46a278d

Browse files
committed
Consistently check conditional extends type for type parameter references
1 parent 0c9db71 commit 46a278d

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10480,29 +10480,14 @@ namespace ts {
1048010480
return result;
1048110481
}
1048210482

10483-
function isPossiblyReferencedInConditionalType(tp: TypeParameter, node: Node) {
10484-
if (isTypeParameterPossiblyReferenced(tp, node)) {
10485-
return true;
10486-
}
10487-
while (node) {
10488-
if (node.kind === SyntaxKind.ConditionalType) {
10489-
if (isTypeParameterPossiblyReferenced(tp, (<ConditionalTypeNode>node).extendsType)) {
10490-
return true;
10491-
}
10492-
}
10493-
node = node.parent;
10494-
}
10495-
return false;
10496-
}
10497-
1049810483
function getTypeFromConditionalTypeNode(node: ConditionalTypeNode): Type {
1049910484
const links = getNodeLinks(node);
1050010485
if (!links.resolvedType) {
1050110486
const checkType = getTypeFromTypeNode(node.checkType);
1050210487
const aliasSymbol = getAliasSymbolForTypeNode(node);
1050310488
const aliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
1050410489
const allOuterTypeParameters = getOuterTypeParameters(node, /*includeThisTypes*/ true);
10505-
const outerTypeParameters = aliasTypeArguments ? allOuterTypeParameters : filter(allOuterTypeParameters, tp => isPossiblyReferencedInConditionalType(tp, node));
10490+
const outerTypeParameters = aliasTypeArguments ? allOuterTypeParameters : filter(allOuterTypeParameters, tp => isTypeParameterPossiblyReferenced(tp, node));
1050610491
const root: ConditionalRoot = {
1050710492
node,
1050810493
checkType,
@@ -11196,9 +11181,12 @@ namespace ts {
1119611181
// type parameter, or if the node contains type queries, we consider the type parameter possibly referenced.
1119711182
if (tp.symbol && tp.symbol.declarations && tp.symbol.declarations.length === 1) {
1119811183
const container = tp.symbol.declarations[0].parent;
11199-
if (findAncestor(node, n => n.kind === SyntaxKind.Block ? "quit" : n === container)) {
11200-
return !!forEachChild(node, containsReference);
11184+
for (let n = node; n !== container; n = n.parent) {
11185+
if (!n || n.kind === SyntaxKind.Block || n.kind === SyntaxKind.ConditionalType && forEachChild((<ConditionalTypeNode>n).extendsType, containsReference)) {
11186+
return true;
11187+
}
1120111188
}
11189+
return !!forEachChild(node, containsReference);
1120211190
}
1120311191
return true;
1120411192
function containsReference(node: Node): boolean {

0 commit comments

Comments
 (0)