-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Cleaner Documentation Comments with ///
#59174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
FWIW unless you have tooling that needs to see the /** Returns the sum of two numbers */
function add(a: number, b: number) {
return a + b
} Personally, I'd prefer a simpler syntax that allows params without tags if you like, but in general supports tags the same as the current design. Something like this. /// Returns the sum of two numbers
/// a - the first number
/// b - the second number
/// @deprecated
function add(a: number, b: number) {
return a + b
} |
@snarbies yes I know that, but my reasoning was to show the nature of it. That it is because of this, and if we move to a more elegant system is better because exactly we don't need proms anymore. |
You don't need them now, was my point. |
I can remove that part from my point, but it still remains that |
It's called JSDoc because it predates Typescript. This is important more more than just historical reasons; it means that many tools other than Typescript also support JSDoc. Even if those other tools can't understand the type annotations, they can still parse the rest of the comments. Switching to |
@nmain I'm not saying this is a replacement, I'm saying that this can be another flavor. If anything, JavaScript can simply be defined in letting the developer have options. It has most features most languages have because it is the only common place where everyone comes and write code. So why should it force only one comment style for documentation? I think it would be great to have this alternative because I don't like |
To be honest I'm a little surprised by the reactions. What I'm trying to say is to just "recognize" an alternative (and preferred) comment style that is "already" implemented and supported, to be a documentation comment as well as the For all the years I have seen code, the I honestly don't get your comments and I mean no one anything bad, it's not a nonsense request: many respected programming languages support it. It's not harming anyone in anyways, breaks no feature, changes nothing in the language, poses no long research/development period on the team (it's probably a one day task, and I think I can even implement it myself and give a PR) and I honestly don't get why should anyone try to stop it from happening. What will you get out of stopping others from having a harmless inexpensive feature? |
|
Please don't take people disagreeing with you personally. People are meant to examine issues here. If somebody has a hard time understanding the benefit, it's natural for them to say so and it's incumbent upon you to articulate why the investment is worthwhile. Plus, any feature, even a teensy tiny little feature, takes non-trivial time and effort to develop, almost always more than it seems at first blush. And any feature can have non-obvious consequences. Most people use an IDE, and the formatting of Adding a second syntax means everyone has to choose one. It creates the opportunities for style/convention wars, adds additional work for people creating documentation tooling, or creates a situation where somebody chooses one style and then finds out after writing several thousand lines of code that a tool in their chain doesn't like that comment style. There is quite a lot of software out there that only understands what we currently have. Fractures in the ecosystem, even small ones, come with a real cost. All other things being equal, I'd have preferred Not trying to rain on your parade. Just trying to convey to you that what you're asking for is not as trivial as it might seem. |
Related: microsoft/tsdoc#160 |
Closing since it is a duplicate of #160 |
Uh oh!
There was an error while loading. Please reload this page.
π Search Terms
"comment", "jsdoc", "documentation", "doc"
β Viability Checklist
β Suggestion
The JSDoc format is both hard to write, and hard to read. More than that it is very messy and designed for a world where there is no compiler present. In the other worlds, languages like Go and Dart have such powerful, and at the same time more beautiful documentation comments that after working with them revisiting TypeScript has become a nightmare of mine. So my suggestion is to employ a better documentation comment, the
///
.π Motivating Example
While to some people TypeScript is an improvement to existing JavaScript projects, for some (which I believe is the most) it was the initial language and there was types from the ground up. And thus all the
@param
parts of the documentation tool are somewhat redundant and a bit ugly to be honest when compared to languages like go where simplicity is the rule. There you simply write a comment above a function and that becomes the function's documentation, that easy. Or in dart, there is a///
comment that has the same semantics, but it also provides a[ClassName]
grammar which links to the name of another class. Markdown like and very basic.Why shouldn't TypeScript have such elegant documentations? You could say:
Instead of
There are somethings here worth noticing:
@param
. Usually, all we want to know from@param
is the type. When the language has the type, then this becomes redundant. It is much more pleasant that we define something in the comment like:/**
feels old! Sorry but it matters, and I hope that you agree, TypeScript is a modern language, it has the most advanced type system in the world, it works on cutting-edge compiler architecture and design, and then it has the comment look of the dark ages. Why should it be such? Why can't we have the beautiful ones that are really easy to write and easy to edit (you can enable multiple coursers in vscode and make a normal comment a documentation comment, or the other way, but good luck doing that with JSDoc)It's called JSDoc! It itself says I'm not the TypeScript doc! TypeScript deserves much more!
Because editing
///
is easier, making tools for it is also easier. I have made an extension for justifying comments so that they are easy to read, uniform, and easy to write. It was so easy to make that for the///
///
comments, but for JSDoc, it was really hard. (I still haven't figured out what should I do) and if TypeScript joins this party, I can make tools like this for my workflow way more easier. And I believe others will too. It is important to enable the community in making tools for what they do. This is an example of a comment justified in Go. I hope that you find it beautiful, and then I can ask: Don't you like to write a comment this clean in TypeScript?π» Use Cases
The text was updated successfully, but these errors were encountered: