File tree 5 files changed +49
-7
lines changed
5 files changed +49
-7
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ title: Changelog
21
21
- Inlining types can now handle more type variants, #2920 .
22
22
- Fixed behavior of ` externalSymbolLinkMappings ` option when URL is set to ` # ` , #2921 .
23
23
- Fixed broken links within module pages when structure-dir router was used, #2928 .
24
+ - Type parameters on JS classes defined with ` @typedef ` now correctly handle the constraint, #2929 .
24
25
- API: ` toString ` on types containing index signatures now behave correctly, #2917 .
25
26
26
27
## v0.28.1 (2025-03-20)
Original file line number Diff line number Diff line change @@ -374,10 +374,15 @@ export function getJsDocComment(
374
374
const tag = comment . getIdentifiedTag ( name , `@${ declaration . tagName . text } ` ) ;
375
375
376
376
if ( ! tag ) {
377
- logger . error (
378
- i18n . failed_to_find_jsdoc_tag_for_name_0 ( name ) ,
379
- declaration ,
380
- ) ;
377
+ // If this is a template tag with multiple declarations, we warned already if there
378
+ // was a comment attached. If there wasn't, then don't error about failing to find
379
+ // a tag because this is unsupported.
380
+ if ( ! ts . isJSDocTemplateTag ( declaration ) ) {
381
+ logger . error (
382
+ i18n . failed_to_find_jsdoc_tag_for_name_0 ( name ) ,
383
+ declaration ,
384
+ ) ;
385
+ }
381
386
} else {
382
387
const result = new Comment ( Comment . cloneDisplayParts ( tag . content ) ) ;
383
388
result . sourcePath = comment . sourcePath ;
Original file line number Diff line number Diff line change @@ -453,12 +453,23 @@ export function createTypeParamReflection(
453
453
getVariance ( param . modifiers ) ,
454
454
) ;
455
455
const paramScope = context . withScope ( paramRefl ) ;
456
- paramRefl . type = param . constraint
457
- ? context . converter . convertType ( paramScope , param . constraint )
458
- : void 0 ;
456
+
457
+ if ( ts . isJSDocTemplateTag ( param . parent ) ) {
458
+ // With a @template tag, the constraint applies only to the
459
+ // first type parameter declared.
460
+ if ( param . parent . typeParameters [ 0 ] . name . text === param . name . text && param . parent . constraint ) {
461
+ paramRefl . type = context . converter . convertType ( paramScope , param . parent . constraint ) ;
462
+ }
463
+ } else {
464
+ paramRefl . type = param . constraint
465
+ ? context . converter . convertType ( paramScope , param . constraint )
466
+ : void 0 ;
467
+ }
468
+
459
469
paramRefl . default = param . default
460
470
? context . converter . convertType ( paramScope , param . default )
461
471
: void 0 ;
472
+
462
473
if ( param . modifiers ?. some ( ( m ) => m . kind === ts . SyntaxKind . ConstKeyword ) ) {
463
474
paramRefl . flags . setFlag ( ReflectionFlag . Const , true ) ;
464
475
}
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @template {number} [T=1]
3
+ */
4
+ export class NumberManager {
5
+ /**
6
+ * @param {T[] } nums
7
+ */
8
+ constructor ( nums ) { }
9
+ }
10
+
11
+ /**
12
+ * @template {number} A, B
13
+ */
14
+ export class EdgeCases {
15
+ }
Original file line number Diff line number Diff line change @@ -2099,4 +2099,14 @@ describe("Issue Tests", () => {
2099
2099
const test3 = query ( project , "InlineArray" ) ;
2100
2100
equal ( test3 . type ?. toString ( ) , "string[]" ) ;
2101
2101
} ) ;
2102
+
2103
+ it ( "#2929 handles type parameters on JS classes" , ( ) => {
2104
+ const project = convert ( ) ;
2105
+ const NumberManager = query ( project , "NumberManager" ) ;
2106
+ equal ( NumberManager . typeParameters ?. map ( t => t . type ?. toString ( ) ) , [ "number" ] ) ;
2107
+ equal ( NumberManager . typeParameters ?. map ( t => t . default ?. toString ( ) ) , [ "1" ] ) ;
2108
+
2109
+ const EdgeCases = query ( project , "EdgeCases" ) ;
2110
+ equal ( EdgeCases . typeParameters ?. map ( t => t . type ?. toString ( ) ) , [ "number" , undefined ] ) ;
2111
+ } ) ;
2102
2112
} ) ;
You can’t perform that action at this time.
0 commit comments