-
-
Notifications
You must be signed in to change notification settings - Fork 736
Support for enum-like use of string literal types #1710
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 looked into doing this, and it is surprisingly annoying to do... the leading trivia on each member of that union is just |
I thought maybe it was just the placement of the pipe characters (at the start of each line, rather than at the end). But it seems to me that the TypeScript parser (which I assume you're using) doesn't expect any comments at all before union type alternatives. I just tried out several variations in the AST explorer, but both leading and trailing comments are always Would it make sense to create an upstream issue for TypeScript? |
We can do it without upstream support, it's just slightly annoying, it sounds like this is something the TypeScript team is willing to improve support for though, I asked about this in the compiler-api channel in the TS Discord, and got this response:
|
At the risk of going slightly off-topic: The documentation comments we write aren't just used with TypeDoc. Developers also rely on tooltips in VS code when using our code. So we try to avoid features that aren't supported by both systems. For instance, we quickly stopped using the (otherwise immensely useful) Returning to this topic: At the moment, we comment the options of a union type within the main comment block of the union type itself. It would be great if there was a way to document these options individually. However, if that way was limited to TypeDoc, using it would actively worsen the development experience in VS code, where this information would simply be missing. This is why I'd prefer a concerted approach (knowing, of course, that this means extra effort for whomever does the coordination). |
I completely agree! Good looking documentation in editors is really important, but I don't really have enough time to coordinate efforts across TypeDoc / VSCode / TypeScript. This change would affect all three. The lack of good editor tooling for string literal enums is the main reason TypeDoc supports the |
I don't think it makes sense for TypeDoc to do this before microsoft/TypeScript#38106, I don't want to encourage patterns in documentation which result in a poor experience in editors. Once the TypeScript issue has been resolved, definitely open to implementing support here. |
Search Terms
enum, string literal type, union type
Problem
Instead of using full enums, TypeScript APIs often use string literal types to achieve a more lightweight API. The following example is straight from the TypeScript documentation:
If I wanted to document this function, this is what I'd write:
However, TypeDoc seems to ignore the doc comments above the individual options. Here is the output with TypeDoc 0.22.4:
Suggested Solution
I'd like TypeDoc to decorate the individual string options with the corresponding doc comments.
The text was updated successfully, but these errors were encountered: