@@ -4435,33 +4435,33 @@ namespace ts {
4435
4435
* for example on a variable declaration whose initializer is a function expression.
4436
4436
*/
4437
4437
export function hasJSDocParameterTags ( node : FunctionLikeDeclaration | SignatureDeclaration ) : boolean {
4438
- return ! ! getFirstJSDocTag ( node , SyntaxKind . JSDocParameterTag ) ;
4438
+ return ! ! getFirstJSDocTag ( node , isJSDocParameterTag ) ;
4439
4439
}
4440
4440
4441
4441
/** Gets the JSDoc augments tag for the node if present */
4442
4442
export function getJSDocAugmentsTag ( node : Node ) : JSDocAugmentsTag | undefined {
4443
- return getFirstJSDocTag ( node , SyntaxKind . JSDocAugmentsTag ) as JSDocAugmentsTag ;
4443
+ return getFirstJSDocTag ( node , isJSDocAugmentsTag ) ;
4444
4444
}
4445
4445
4446
4446
/** Gets the JSDoc class tag for the node if present */
4447
4447
export function getJSDocClassTag ( node : Node ) : JSDocClassTag | undefined {
4448
- return getFirstJSDocTag ( node , SyntaxKind . JSDocClassTag ) as JSDocClassTag ;
4448
+ return getFirstJSDocTag ( node , isJSDocClassTag ) ;
4449
4449
}
4450
4450
4451
4451
/** Gets the JSDoc return tag for the node if present */
4452
4452
export function getJSDocReturnTag ( node : Node ) : JSDocReturnTag | undefined {
4453
- return getFirstJSDocTag ( node , SyntaxKind . JSDocReturnTag ) as JSDocReturnTag ;
4453
+ return getFirstJSDocTag ( node , isJSDocReturnTag ) ;
4454
4454
}
4455
4455
4456
4456
/** Gets the JSDoc template tag for the node if present */
4457
4457
export function getJSDocTemplateTag ( node : Node ) : JSDocTemplateTag | undefined {
4458
- return getFirstJSDocTag ( node , SyntaxKind . JSDocTemplateTag ) as JSDocTemplateTag ;
4458
+ return getFirstJSDocTag ( node , isJSDocTemplateTag ) ;
4459
4459
}
4460
4460
4461
4461
/** Gets the JSDoc type tag for the node if present and valid */
4462
4462
export function getJSDocTypeTag ( node : Node ) : JSDocTypeTag | undefined {
4463
4463
// We should have already issued an error if there were multiple type jsdocs, so just use the first one.
4464
- const tag = getFirstJSDocTag ( node , SyntaxKind . JSDocTypeTag ) as JSDocTypeTag ;
4464
+ const tag = getFirstJSDocTag ( node , isJSDocTypeTag ) ;
4465
4465
if ( tag && tag . typeExpression && tag . typeExpression . type ) {
4466
4466
return tag ;
4467
4467
}
@@ -4480,7 +4480,7 @@ namespace ts {
4480
4480
* tag directly on the node would be returned.
4481
4481
*/
4482
4482
export function getJSDocType ( node : Node ) : TypeNode | undefined {
4483
- let tag : JSDocTypeTag | JSDocParameterTag = getFirstJSDocTag ( node , SyntaxKind . JSDocTypeTag ) as JSDocTypeTag ;
4483
+ let tag : JSDocTypeTag | JSDocParameterTag | undefined = getFirstJSDocTag ( node , isJSDocTypeTag ) ;
4484
4484
if ( ! tag && isParameter ( node ) ) {
4485
4485
tag = find ( getJSDocParameterTags ( node ) , tag => ! ! tag . typeExpression ) ;
4486
4486
}
@@ -4500,7 +4500,7 @@ namespace ts {
4500
4500
}
4501
4501
4502
4502
/** Get all JSDoc tags related to a node, including those on parent nodes. */
4503
- export function getJSDocTags ( node : Node ) : ReadonlyArray < JSDocTag > | undefined {
4503
+ export function getJSDocTags ( node : Node ) : ReadonlyArray < JSDocTag > {
4504
4504
let tags = ( node as JSDocContainer ) . jsDocCache ;
4505
4505
// If cache is 'null', that means we did the work of searching for JSDoc tags and came up with nothing.
4506
4506
if ( tags === undefined ) {
@@ -4510,17 +4510,14 @@ namespace ts {
4510
4510
}
4511
4511
4512
4512
/** Get the first JSDoc tag of a specified kind, or undefined if not present. */
4513
- function getFirstJSDocTag ( node : Node , kind : SyntaxKind ) : JSDocTag | undefined {
4514
- const tags = getJSDocTags ( node ) ;
4515
- return find ( tags , doc => doc . kind === kind ) ;
4513
+ function getFirstJSDocTag < T extends JSDocTag > ( node : Node , predicate : ( tag : JSDocTag ) => tag is T ) : T | undefined {
4514
+ return find ( getJSDocTags ( node ) , predicate ) ;
4516
4515
}
4517
4516
4518
4517
/** Gets all JSDoc tags of a specified kind, or undefined if not present. */
4519
4518
export function getAllJSDocTagsOfKind ( node : Node , kind : SyntaxKind ) : ReadonlyArray < JSDocTag > | undefined {
4520
- const tags = getJSDocTags ( node ) ;
4521
- return filter ( tags , doc => doc . kind === kind ) ;
4519
+ return getJSDocTags ( node ) . filter ( doc => doc . kind === kind ) ;
4522
4520
}
4523
-
4524
4521
}
4525
4522
4526
4523
// Simple node tests of the form `node.kind === SyntaxKind.Foo`.
@@ -5163,6 +5160,10 @@ namespace ts {
5163
5160
return node . kind === SyntaxKind . JSDocAugmentsTag ;
5164
5161
}
5165
5162
5163
+ export function isJSDocClassTag ( node : Node ) : node is JSDocClassTag {
5164
+ return node . kind === SyntaxKind . JSDocClassTag ;
5165
+ }
5166
+
5166
5167
export function isJSDocParameterTag ( node : Node ) : node is JSDocParameterTag {
5167
5168
return node . kind === SyntaxKind . JSDocParameterTag ;
5168
5169
}
0 commit comments