Skip to content

Commit ec7ddf8

Browse files
committed
Checking is 1/3 done or so.
Now I'm going to go rename some members to be more uniform. I hate unnnecessary conditionals.
1 parent 7737c7c commit ec7ddf8

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5355,9 +5355,9 @@ namespace ts {
53555355
return unknownType;
53565356
}
53575357

5358-
const declaration = <JSDocTypedefTag | TypeAliasDeclaration>find(symbol.declarations, d =>
5359-
d.kind === SyntaxKind.JSDocTypedefTag || d.kind === SyntaxKind.TypeAliasDeclaration);
5360-
const typeNode = declaration.kind === SyntaxKind.JSDocTypedefTag ? declaration.typeExpression : declaration.type;
5358+
const declaration = <JSDocTypedefTag | JSDocCallbackTag | TypeAliasDeclaration>find(symbol.declarations, d =>
5359+
isJSDocTypeAlias(d) || d.kind === SyntaxKind.TypeAliasDeclaration);
5360+
const typeNode = isJSDocTypedefTag(declaration) ? declaration.typeExpression : isJSDocCallbackTag(declaration) ? declaration.signature : declaration.type;
53615361
// If typeNode is missing, we will error in checkJSDocTypedefTag.
53625362
let type = typeNode ? getTypeFromTypeNode(typeNode) : unknownType;
53635363

@@ -7575,24 +7575,25 @@ namespace ts {
75757575
*/
75767576
function getTypeFromTypeAliasReference(node: NodeWithTypeArguments, symbol: Symbol, typeArguments: Type[]): Type {
75777577
const type = getDeclaredTypeOfSymbol(symbol);
7578+
// TODO: call getEffectiveTypeParameterDeclarations here and upgrade it to understand in-comment template tags as type parameters
75787579
const typeParameters = getSymbolLinks(symbol).typeParameters;
75797580
if (typeParameters) {
75807581
const numTypeArguments = length(node.typeArguments);
75817582
const minTypeArgumentCount = getMinTypeArgumentCount(typeParameters);
75827583
if (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length) {
75837584
error(node,
7584-
minTypeArgumentCount === typeParameters.length
7585-
? Diagnostics.Generic_type_0_requires_1_type_argument_s
7586-
: Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments,
7587-
symbolToString(symbol),
7588-
minTypeArgumentCount,
7589-
typeParameters.length);
7585+
minTypeArgumentCount === typeParameters.length
7586+
? Diagnostics.Generic_type_0_requires_1_type_argument_s
7587+
: Diagnostics.Generic_type_0_requires_between_1_and_2_type_arguments,
7588+
symbolToString(symbol),
7589+
minTypeArgumentCount,
7590+
typeParameters.length);
75907591
return unknownType;
75917592
}
75927593
return getTypeAliasInstantiation(symbol, typeArguments);
75937594
}
75947595
return checkNoTypeArguments(node, symbol) ? type : unknownType;
7595-
}
7596+
}
75967597

75977598
function getTypeReferenceName(node: TypeReferenceType): EntityNameOrEntityNameExpression | undefined {
75987599
switch (node.kind) {

src/compiler/utilities.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,10 @@ namespace ts {
17721772
((node as JSDocFunctionType).parameters[0].name as Identifier).escapedText === "new";
17731773
}
17741774

1775+
export function isJSDocTypeAlias(node: Node): node is JSDocTypedefTag | JSDocCallbackTag {
1776+
return node.kind === SyntaxKind.JSDocTypedefTag || node.kind === SyntaxKind.JSDocCallbackTag;
1777+
}
1778+
17751779
function getSourceOfAssignment(node: Node): Node {
17761780
return isExpressionStatement(node) &&
17771781
node.expression && isBinaryExpression(node.expression) &&
@@ -5435,6 +5439,14 @@ namespace ts {
54355439
export function isJSDocTypeLiteral(node: Node): node is JSDocTypeLiteral {
54365440
return node.kind === SyntaxKind.JSDocTypeLiteral;
54375441
}
5442+
5443+
export function isJSDocCallbackTag(node: Node): node is JSDocCallbackTag {
5444+
return node.kind === SyntaxKind.JSDocCallbackTag;
5445+
}
5446+
5447+
export function isJSDocSignature(node: Node): node is JSDocSignature {
5448+
return node.kind === SyntaxKind.JSDocSignature;
5449+
}
54385450
}
54395451

54405452
// Node tests

0 commit comments

Comments
 (0)