Skip to content

Commit

Permalink
Consistently check conditional extends type for type parameter refere…
Browse files Browse the repository at this point in the history
…nces
  • Loading branch information
ahejlsberg committed May 10, 2019
1 parent 0c9db71 commit 46a278d
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/compiler/checker.ts
Expand Up @@ -10480,29 +10480,14 @@ namespace ts {
return result;
}

function isPossiblyReferencedInConditionalType(tp: TypeParameter, node: Node) {
if (isTypeParameterPossiblyReferenced(tp, node)) {
return true;
}
while (node) {
if (node.kind === SyntaxKind.ConditionalType) {
if (isTypeParameterPossiblyReferenced(tp, (<ConditionalTypeNode>node).extendsType)) {
return true;
}
}
node = node.parent;
}
return false;
}

function getTypeFromConditionalTypeNode(node: ConditionalTypeNode): Type {
const links = getNodeLinks(node);
if (!links.resolvedType) {
const checkType = getTypeFromTypeNode(node.checkType);
const aliasSymbol = getAliasSymbolForTypeNode(node);
const aliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
const allOuterTypeParameters = getOuterTypeParameters(node, /*includeThisTypes*/ true);
const outerTypeParameters = aliasTypeArguments ? allOuterTypeParameters : filter(allOuterTypeParameters, tp => isPossiblyReferencedInConditionalType(tp, node));
const outerTypeParameters = aliasTypeArguments ? allOuterTypeParameters : filter(allOuterTypeParameters, tp => isTypeParameterPossiblyReferenced(tp, node));
const root: ConditionalRoot = {
node,
checkType,
Expand Down Expand Up @@ -11196,9 +11181,12 @@ namespace ts {
// type parameter, or if the node contains type queries, we consider the type parameter possibly referenced.
if (tp.symbol && tp.symbol.declarations && tp.symbol.declarations.length === 1) {
const container = tp.symbol.declarations[0].parent;
if (findAncestor(node, n => n.kind === SyntaxKind.Block ? "quit" : n === container)) {
return !!forEachChild(node, containsReference);
for (let n = node; n !== container; n = n.parent) {
if (!n || n.kind === SyntaxKind.Block || n.kind === SyntaxKind.ConditionalType && forEachChild((<ConditionalTypeNode>n).extendsType, containsReference)) {
return true;
}
}
return !!forEachChild(node, containsReference);
}
return true;
function containsReference(node: Node): boolean {
Expand Down

0 comments on commit 46a278d

Please sign in to comment.