englercj / tsd-jsdoc

Compiles JSDoc annotated JavaScript into a Typescript Definition file (.d.ts)
MIT License
316 stars 42 forks source link

`@template` tag does not generate generic parameters #134

Closed thw0rted closed 4 years ago

thw0rted commented 4 years ago

I'm trying to document generics and while the tags are correctly interpreted by Typescript directly, tsd-jsdoc is not applying type parameters in its output.

I put together a simple repro and nothing I do there is able to get the output to include type parameters in the declaration.


Once this is worked out, I also wanted to see if there is supposed to be any syntax for specifying a default value for type parameters, as in MyClass<T extends Function = Function>. That isn't listed on the Closure documentation about Generics and it sounds like the TS team is still debating, so I could open a separate issue if need be.

englercj commented 4 years ago

There is an example in the tests that successfully generates a class with a generic template: https://github.com/englercj/tsd-jsdoc/blob/d75937645ed7eb7f162652594cd27913e7bcba95/test/fixtures/namespace_all.js#L7-L15

thw0rted commented 4 years ago

Welp, it's right there on the front page 😳

If you want to use supported ClosureCompiler features, you also need to specify this module as a pluginin your JSON configuration

Adding "plugins": [ "./node_modules/tsd-jsdoc/dist/plugin" ], to my ts-conf.json immediately resolved the issue. I'm sorry I missed that, and thanks for pointing me in the right direction, @englercj .

Should I open a second issue about supporting type parameter bounds and default values? Currently, whatever follows @template is shoved into the type parameter verbatim, so I can actually write @template FuncType extends Function = Function and it compiles to declare class GenericClass<SomeType extends Function = Function>. This is what I want, but it's not correct per the Closure spec or Typescript's own interpretation of the @template tag. Both of those support @template {Function} FuncType, and as far as I can tell neither of them actually have a syntax for supplying a default value at all.