From ec7ddf88a4e4bb432d27c9b33c9ee25e5a80c47c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 1 May 2018 15:34:26 -0700 Subject: [PATCH] Checking is 1/3 done or so. Now I'm going to go rename some members to be more uniform. I hate unnnecessary conditionals. --- src/compiler/checker.ts | 21 +++++++++++---------- src/compiler/utilities.ts | 12 ++++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d825b0d9717..2ca479492b5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5355,9 +5355,9 @@ namespace ts { return unknownType; } - const declaration = find(symbol.declarations, d => - d.kind === SyntaxKind.JSDocTypedefTag || d.kind === SyntaxKind.TypeAliasDeclaration); - const typeNode = declaration.kind === SyntaxKind.JSDocTypedefTag ? declaration.typeExpression : declaration.type; + const declaration = find(symbol.declarations, d => + isJSDocTypeAlias(d) || d.kind === SyntaxKind.TypeAliasDeclaration); + const typeNode = isJSDocTypedefTag(declaration) ? declaration.typeExpression : isJSDocCallbackTag(declaration) ? declaration.signature : declaration.type; // If typeNode is missing, we will error in checkJSDocTypedefTag. let type = typeNode ? getTypeFromTypeNode(typeNode) : unknownType; @@ -7575,24 +7575,25 @@ namespace ts { */ function getTypeFromTypeAliasReference(node: NodeWithTypeArguments, symbol: Symbol, typeArguments: Type[]): Type { const type = getDeclaredTypeOfSymbol(symbol); + // TODO: call getEffectiveTypeParameterDeclarations here and upgrade it to understand in-comment template tags as type parameters const typeParameters = getSymbolLinks(symbol).typeParameters; if (typeParameters) { const numTypeArguments = length(node.typeArguments); const minTypeArgumentCount = getMinTypeArgumentCount(typeParameters); if (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length) { error(node, - minTypeArgumentCount === typeParameters.length - ? Diagnostics.Generic_type_0_requires_1_type_argument_s - : Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments, - symbolToString(symbol), - minTypeArgumentCount, - typeParameters.length); + minTypeArgumentCount === typeParameters.length + ? Diagnostics.Generic_type_0_requires_1_type_argument_s + : Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments, + symbolToString(symbol), + minTypeArgumentCount, + typeParameters.length); return unknownType; } return getTypeAliasInstantiation(symbol, typeArguments); } return checkNoTypeArguments(node, symbol) ? type : unknownType; - } + } function getTypeReferenceName(node: TypeReferenceType): EntityNameOrEntityNameExpression | undefined { switch (node.kind) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 04db855d4f8..e41502c9e6d 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1772,6 +1772,10 @@ namespace ts { ((node as JSDocFunctionType).parameters[0].name as Identifier).escapedText === "new"; } + export function isJSDocTypeAlias(node: Node): node is JSDocTypedefTag | JSDocCallbackTag { + return node.kind === SyntaxKind.JSDocTypedefTag || node.kind === SyntaxKind.JSDocCallbackTag; + } + function getSourceOfAssignment(node: Node): Node { return isExpressionStatement(node) && node.expression && isBinaryExpression(node.expression) && @@ -5435,6 +5439,14 @@ namespace ts { export function isJSDocTypeLiteral(node: Node): node is JSDocTypeLiteral { return node.kind === SyntaxKind.JSDocTypeLiteral; } + + export function isJSDocCallbackTag(node: Node): node is JSDocCallbackTag { + return node.kind === SyntaxKind.JSDocCallbackTag; + } + + export function isJSDocSignature(node: Node): node is JSDocSignature { + return node.kind === SyntaxKind.JSDocSignature; + } } // Node tests