From 9ef417b846694bb609e6d2a36b90b87b4e58cc34 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 11 Oct 2017 16:02:58 -0700 Subject: [PATCH] Account for type queries in type literals --- src/compiler/checker.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ed131c8936c..9224b6afd7c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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(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(node) === tp; + case SyntaxKind.TypeQuery: + return true; + } + return forEachChild(node, containsReference); } }