-
Notifications
You must be signed in to change notification settings - Fork 137
Triple slash support (C# style) #160
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
I agree that Unfortunately there are a couple problems with such a change:
From a non-standard perspective, it would be reasonable to request for the parser library API to accept the raw lines as its input. In the current implementation we remove the |
Coming from Rust, the triple-slash syntax is used everywhere and I've come to appreciate it a lot more than the usual block-style comments. I think that there's a bit of a difference between allowing line and block comments and adding multiple formats for the documentation itself. I absolutely agree that the actual There's a reason why languages offer both block and line comments and I think that it doesn't really split the ecosystem to allow both. Consistency within a project can easily be established through linting, and I don't think it requires many mental hurdles to jump through to understand. |
Is there a specific benefit, though, beyond looking more like Rust source code? There are nontrivial costs:
We can do this. They are certainly easier problems than other work we've already done. But what do we get from this investment? |
It's nice because:
Also, the case you mentioned: what if someone types Is it worth it? I can't say. If I had more time to spend on this it'd make sense to run a community poll. But I figured I'd add my comments on this because the issue was open and there wasn't that much detail here. :) |
I realize that this proposal would also require separate fixes for each tool that supports TSDoc, since the TSDoc library itself does not find comments within a source file. That job is always handled by the caller (because they do it while parsing API signatures): For example, our API demo does it like this (using the TypeScript compiler API): tsdoc/api-demo/src/advancedDemo.ts Lines 69 to 74 in b2bdf5c
Whereas the TSDoc Playground does it like this (using the Monaco editor control): tsdoc/eslint-plugin/src/index.ts Lines 98 to 107 in b2bdf5c
The TypeScript compiler itself provides a bunch of APIs with names like All these parsers would need to be updated to recognize /// ```
/// /* code snippet */
/// ``` Wheres in TSDoc it needs to get escaped like:
I personally agree that
We could ask automobile owners: "How do you feel about a switch that lets you move your steering wheel to the left side OR the right side? The same car can drive in any country!" People might vote yes. It has some marginal value, and nobody's obligated to use it. But we should also poll the car manufacturers to see if they are willing to build it. 🙂 |
We've been thinking a bit about this on the TS side too: microsoft/TypeScript#39930 |
Strong +1 for '///' style comments. I love commenting stuff. But I also like the code to be reasonably compact. For me, sure, a single /// comment and a 1-line /** comment */ comment is the same. But once you move the two lines...
Pedantic, but why would I be a programmer if I wasn't 😎 |
The "it's slightly less keystrokes!" argument didn't seem very compelling. But there is a particularly thorny problem of Consider this example: /**
* Strips the comments from an input string:
*
* @example
* ```ts
* // prints " some text":
* console.log(stripComments("/* a comment */ some text");
* ```
*/
function stripComments(code: string): string; You will find that this is a syntax error because /**
* Strips the comments from an input string:
* @param code - the input string
*
* @example
* ```ts
* // prints " some text":
* console.log(stripComments("/* a comment *
*+/ some text");
* ```
*/
function stripComments(code: string): string; It is a clunky solution, but I've become convinced it's the only complete solution to this problem. Whereas nesting /// Strips the comments from an input string:
/// @param code - the input string
///
/// @example
/// ```ts
/// // prints " some text":
/// console.log(stripComments("/* a comment */ some text");
/// ```
function stripComments(code: string): string; However moving from
As a conversation piece, this is how Sandcastle would represent the above docs: /// <summary>Strips the comments from an input string:</summary>
/// <param name="code">the input string</param>
///
/// <example>
/// <code lang="ts">
/// // prints " some text":
/// console.log(stripComments("/* a comment */ some text");
/// </code>
/// </example>
function stripComments(code: string): string; It's verbose. But having personally written a lot of Sandcastle docs back in the day, it does have the upside that you never have to guess how your markup will get rendered on the website. And it's super easy to correctly parse a comment containing unsupported markup. But... are any TypeScript devleopers not horrified by this prospect? 😁 |
A further advantage of This makes authoring multi-line code blocks, e.g. for I haven't yet found any setting / extension that fixes this indentation offset in VS Code. /**
* The back ticks of the following code fence start at column 3.
* This means that the first level of indentation starts at column 5.
*
* Hitting the `Tab` key always inserts even indentation and thus indents
* incorrectly.
*
* ```ts
* const foo = {
* expected: true, // ✅ Col 5: Manual correct indentation by two spaces.
* tabPressedOnce: true, // ❌ Col 4: 1 x `Tab` indents by one space.
* tabPressedTwice: true, // ❌ Col 6: 2 x `Tab` indents by three spaces.
* };
* ```
*/ |
It seems that // .prettierrc
{
"plugins": ["prettier-plugin-jsdoc"],
"tsdoc": true
} |
This may be a chicken-and-egg issue where the cost of using them is high enough (in terms of losing access to doc generation and IDE support) that even packages that would normally choose to do so can't. I'll say that I would certainly use them for Sass's TypeScript documentation if I could, and I've even looked around to see if there are packages I could use to compile I understand the perspective that ergonomics alone aren't necessarily a reason to add a totally separate way of writing comments, but I think nested comments push the case for |
Even with a transition to
The industry has moved on. Rust, Dart, Go, Swift, C#, and F# all use slashes. |
IMO not supporting |
Just for a little perspective on my particular workflow: because the So I often comment my functions, but I only use The discussion about why we shouldn't have this seems a lot like the classic "well it wouldn't be perfect, so it's not worth doing at all" fallacy. And with ever-growing market share for modern languages like Rust, C#, Dart, Swift, Go, etc. that all use the elegance of |
I came from #166 and similar issues and also agree that supporting But there's a slight issue with deprecating or even not supporting the const readonlyTuple = /** @type {const} */ ([1,2,3]); For longer tuples with line breaks between items you can even do this: const readonlyTuple = /** @type {const} */ (
[
1,
2,
3
]
); This could be written with const readonlyTuple = /// @type {const}
([1,2,3]); const readonlyTuple = /// @type {const}
(
[
1,
2,
3
]
); but of course because So my proposal is to think about this little issue if support for const readonlyTuple = ([1,2,3]); /// @type {const} const readonlyTuple = ([
1,
2,
3
]); /// @type {const} The above is much closer to the "real" I also realize this is mostly about JS and JSDoc and not TS and TSDoc, but I think such support for |
Please support triple slashes
Triple slash documentation is much cleaner in my opinion.
E.g. Dart also supports it: https://www.dartlang.org/guides/language/effective-dart/documentation#do-use--doc-comments-to-document-members-and-types
The text was updated successfully, but these errors were encountered: