Account for type queries in type literals

This commit is contained in:
Anders Hejlsberg
2017-10-11 16:02:58 -07:00
parent d815ba13f8
commit 9ef417b846

View File

@@ -8290,20 +8290,25 @@ namespace ts {
function isTypeParameterPossiblyReferenced(tp: TypeParameter, node: Node) {
// If the type parameter doesn't have exactly one declaration, if there are invening statement blocks
// between the node and the type parameter declaration, or if the node contains actual references to the
// type parameter, we consider the type parameter possibly referenced.
// between the node and the type parameter declaration, if the node contains actual references to the
// 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 tp.isThisType ? forEachChild(node, checkThis) : forEachChild(node, checkIdentifier);
return forEachChild(node, containsReference);
}
}
return true;
function checkThis(node: Node): boolean {
return node.kind === SyntaxKind.ThisType || forEachChild(node, checkThis);
}
function checkIdentifier(node: Node): boolean {
return node.kind === SyntaxKind.Identifier && isPartOfTypeNode(node) && getTypeFromTypeNode(<TypeNode>node) === tp || forEachChild(node, checkIdentifier);
function containsReference(node: Node): boolean {
switch (node.kind) {
case SyntaxKind.ThisType:
return tp.isThisType;
case SyntaxKind.Identifier:
return !tp.isThisType && isPartOfTypeNode(node) && getTypeFromTypeNode(<TypeNode>node) === tp;
case SyntaxKind.TypeQuery:
return true;
}
return forEachChild(node, containsReference);
}
}