Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
No types in comments? #180
Comments
|
In TypeScript, types are specified using in the language itself. It doesn't make sense to declare them in the comment. When people are writing new TypeScript code using TSDoc, it's a mistake to put types in a comment. The initial implementation of the TSDoc parser is "strict" and reports an error. But this practice is valid with JSDoc, since it was designed for JavaScript. Because of that, it's somewhat common to find that notation in legacy TypeScript code. To accommodate this, the plan is to implement a "lax" mode that allows the TSDoc parser to accept these notations. We'd recommend to use "strict" mode for new projects, and "lax" mode for existing projects. That's the plan, but the first priority is to finish the strict TSDoc specification. It's close to being done, but there's a few major changes that need to get incorporated before the "1.0" release:
We're making steady progress on these things, but it takes time. |
This is normally true.
Nice! Always great to hear progress being made. :) The reason I want source-code-agnostic JS/TSDoc is to be very specific about my docs and how they are presented. I'd like comments to be absolute source of truth for my docs, regardless source code (though a case-by-case opt-in feature could be nice). Unfortunately all JSDoc tools I've tried fumble on TS code because they rely on the source (and an associated AST). What I want to do is the following sort of documentation. Under the assumption that all classes in the project I'm documenting are mixable classes, then most files will look something like this:
|
|
I see what you mean. I'll start by saying that mixins are overcomplicated, difficult to debug, and difficult for users to understand. Nobody should be excited about mixins. I really mean that! That said, now let's talk about how mixins worked awesome for my own project API Extractor. The TL;DR:
I didn't pursue this feature because API Extractor is literally the only project where I can justify using mixins. But if you like this idea, we could do a quick PR to add the |
The one in Leafdoc is great; it supports multiple inheritance (whether that's class mixins, concatenation of objects, or whatever) that can be documented across multiple files, and is source agnostic. An What would a simple example of |
|
See the other issue I linked above |
|
Ah, thanks. It seems like a little bit more complicated than I'd like. I think of TypeScript as an implementation detail for the mixins. I'd like to document them without regards to the specific language, avoiding to document all the TypeScript-specific mechanisms that make up a mixin in TypeScript. I really like how it works in Leafdoc: /**
* @class Foo
*/
blah blah, this syntax { is ) not ) any & valid ] code
/**
* This method return a number and has a string param
* @method fooMethod: number
* @param name: string
*/
blah blah, this syntax { is ) not ) any & valid ] code
/**
* @class Bar
*/
blah blah, this syntax { is ) not ) any & valid ] code
/**
* @method barMethod: void
* @param shouldDoSomething: boolean
*/
blah blah, this syntax { is ) not ) any & valid ] code
/**
* This class extends from both Foo and Bar
* @class Baz
* @inherits Foo
* @inherits Bar
*/
blah blah, this syntax { is ) not ) any & valid ] code
/**
* @method bazMethod: void
*/
blah blah, this syntax { is ) not ) any & valid ] codeHere's the example output of the above example (my output template is WIP, it'll look better later!): With this particular template, the inherited methods are visible in This simple system allows documenting compositional patterns, without being tied to the source ( I really like the simplicity of Leafdoc, but it would be nice to be able to achieve the same with a standard syntax like JS/TSDoc, because then text editors (f.e. VS Code) have official support for them. |
|
That makes sense. However your examples only use primitive types like What will you do with the parameter whose type is |
the comment parser is source agnostic so it doesn't matter much: I could put anything in place of It is flexible, allowing my docs to have the meaning that I want them to have. I can determine how to link to that class But anywho, I decided to just make my own JSDoc parser using Later it would be nice to upgrade it to a lexer that works over a stream of incoming text, for speed. A higher-level tool could choose to be source-aware and to parse the types, parse the description with specific syntax like For my case though, I'll take the strings and make something minimal and source agnostic, with markdown handling for the descriptions. TypeScript supports types in the JSDoc comments. I wonder what it's using for that. Maybe it's all just built into TypeScript, but it'd be nice if it could be used standalone... |
|
I think a generic foundation may be good for tools to build upon (f.e. a type-aware source-aware tool). Plus, it'd be nice to also document anything in a project, like CSS, HTML, Less, shell scripts, PHP, Ruby, or other sorts of files, using the same doc tool. |
|
It sounds like you are after JSDoc with the |
|
Looking forward to trying the "lax" mode once that's out. :) |
|
@Gerrit0 Oh interesting, I hadn't seen that plugin before. I'll check it out... EDIT: Ironically, the JSDoc site doesn't document the API (and plugin hooks), or at least there's no immediately obvious link to it. I do see JSDoc comments in the source though. |
|
Everything I try has some critical issue. Writing /**
* @class Foo
* This is a cool class.
*/causes JSDoc to break, and output nothing after it reaches that comment. You'd think, that it could at least not fail just because It'd be great to have a tool that reads comments, and always returns the content of every comment in some understandable form without tripping up on insignificant details like above. EDIT: more rant about inconsistent JSDoc syntax:I don't like the inconsistencies in the syntax across tags. From their docs: /**
* @function {foo} - This has the name of the function, "foo", inside the curlies. ????
* @param {string} bar - But this one has the type inside the curlies and the name outside!!!
*/
function foo(bar) {}With my above proposed regex solution I linked, every tag will have the same syntax and structure, and always output something. Easy! |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.




I tried the playground, but when I try something like
it gives