-
Notifications
You must be signed in to change notification settings - Fork 137
RFC: Specify that doc comments are allowed on simple union types #164
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
Does the compiler preserve these comments in the emitted .d.ts files? I recall sometimes comments in certain places get discarded. TSDoc itself doesn't (yet) dictate very specifically where comments can appear. That is determined by the documentation tool that uses the TSDoc library. Which tool are you using? |
Hi there, I have the same thing. I am using String Literal types to define classnames and would love to populate with some more information. So basically: type TClassnames =
| 'bg-color-red-500'
| 'bg-color-red-600' I would love to populate the docs on the right side of the intellisense: This is how we can document with properties: Which would be amazing to have on string literals |
Any progress on this issue? |
To answer my earlier question, the TypeScript compiler does preserve these comments in the .d.ts file: export declare type InputType =
/** the TSDoc doesn't work for num1, but I'd like it to */
'num1'
/** the TSDoc doesn't work for num2, but I'd also like it to */
| 'num2'; So I think this feature seems pretty reasonable. 👍 But as mentioned previously, the TSDoc standard can specify that "yes this is an appropriate place to put a comment", but the TSDoc library only parses comments. It does not parse API signatures. That part is handled by your documentation tool such as API Extractor or TypeDoc. So you'd need to open an issue to request this feature for the documentation tool. |
If this is specified as valid, what would documented types look like? Right now both api-extractor and typedoc just display the type. Do we need special casing for unions? Are doc comments allowed on union types within another type? Would this result in users expecting to be able to include comments almost anywhere within a type and have them be picked up? type Messy = [ /** a */ 1, /** b */ 2 | /** c */ 3] |
@Gerrit0 my thinking to restrict this feature to a very special pattern that is commonly used like an enum. We could give it a name like "union enum". For example, these would be union enums: /**
* A standard system color.
*/
export type Color =
/**
* The color `#ff0000`
*/
'red' | // do we care whether "|" is before/after the comment? Not really
/**
* The color `#00ff00`
*/
'green'
/**
* The color `#0000ff`
*/
| 'blue';
/**
* A binary digit.
*/
export type Bit = /** zero */ 0 | /** one*/ 1; But it's optional. For example, maybe a documentation tool only treats a type as an "union enum" if at least one of the members has a And it would NOT apply to any other generalized expressions, not even this sort of thing: // NOT a union enum:
type Mammal = Cat | Dog | Horse; For the most part, such a feature would be a feature request for your particular documentation tool. If TSDoc "supports" this feature, its role is merely to:
|
Edit: I misunderstood - see the comment below. |
Note: TypeDoc != TSDoc. This hasn't been added to the TSDoc standard yet, but TypeDoc plans to support it. Other documentation generators might not necessarily support it. |
Therefore, it was the 2nd case - me misunderstanding this basic thing. Sorry for the mistake, and thanks for the clarification! As it is related, I'll rewrite below the comment I made on the official TypeScript repo. This is an underrated feature. Nowadays, a lot of Here are a few real-world use-cases: React Native CSS<Text style={{
color: 'blue',
alignSelf: 'center',
}}> This is a blue text </Text> Adding string comments would simplify the understanding of each possibility (each color, each possible alignments). This is applicable to all properties with a defined set of string values. Configuration filesFor example, let's take a {
"module": "commonjs"
} Currently, the documentation looks like this: While we know all the possible options, there is no way to understand what they actually do. String comments could tell explicitly the user what each option is supposed to change. This is applicable to all configuration files that are made with TS, not only Material-UIMaterial-UI relies a lot on string enumerations, but they are not always easy to understand. <Button variant="contained"> My Button </Button> In the above example, while This is applicable to all React props with a defined set of string values. In conclusion, I think it's a very good idea, and it could simplify documentation in a lot of projects. |
Any progress on this issue today, plz |
Is this feature difficult to implement? |
FWIW, this doesn't appear to work for complex union/intersection types either until you've defined enough properties to resolve the full type, e.g.
|
When adding the `resolvedStatus` to the LocationData API, I noticed that it wasn't relevant to the ThreadList, as the ThreadList doesn't have pagination and fetches all threads anyway - doing all filtering within the component. So I created a union type. This is not great 1. because it doesn't enforce consistency in our API filters, and 2. because the docs look bad (I had not noticed). TsDoc can't handle union types and it's a known bug (microsoft/tsdoc#164). This PR moves the `resolvedStatus` within the ThreadListFilter type, then goes through all its uses and decides on whether to omit it or not. Test Plan: Tested ThreadedComments with all 4 tab options and they worked correctly. Then tested the ThreadedComments by switching the underlying API to use the deprecated parameter, which also worked as expected. Also, docs look really nice again :) Reviewers: flooey, jwatzman, km-nur Reviewed By: km-nur Pull Request: https://github.com/getcord/monorepo/pull/6436 monorepo-commit: e8a3e6ed8846cff9baeffc16e7e1dabdb7e42cb7
just wait for tsdoc to support template literal microsoft/tsdoc#164
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I can't find any documentation on adding tsdocs to a typescript string literal type. I was wondering if the following is possible:
I'm not 100% tied to using string literal types, so if there is another way to do this with
enums
, etc., I'd love to learn 😄If the above is not currently possible, I'd love to work to add it to tsdoc (with some guidance 😄).
Thanks!
The text was updated successfully, but these errors were encountered: