Skip to content
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

How to document types? (Unions and Intersection Types) #207

Closed
mrousavy opened this issue Mar 18, 2021 · 3 comments
Closed

How to document types? (Unions and Intersection Types) #207

mrousavy opened this issue Mar 18, 2021 · 3 comments

Comments

@mrousavy
Copy link
Contributor

Search Terms

type, export type, types, interface, interfaces, union type, intersection type, unions

Problem

Can't document union types

It is not possible to document the individual values of union types, so I have to adjust the description to manually list them:

/**
 * Represents the camera device position.
 *
 * * `"back"`: Indicates that the device is physically located on the back of the system hardware
 * * `"front"`: Indicates that the device is physically located on the front of the system hardware
 *
 * #### iOS only
 * * `"unspecified"`: Indicates that the device's position relative to the system hardware is unspecified
 *
 * #### Android only
 * * `"external"`: The camera device is an external camera, and has no fixed facing relative to the device's screen. (Android only)
 */
export type CameraPosition = 'front' | 'back' | 'unspecified' | 'external';

Is there a better solution for this so I can correctly document each union (front, back, ...) with TypeDoc checking if I missed anything and even allowing me to link to it?

No "types" category in output

Documenting an interface is easy;

/**
 * document Point here
 */
export interface Point {
  /**
   * document x here
   */ 
  x: number;
  /**
   * document x here
   */ 
  y: number;
}

...and TypeDoc places it under the "Interfaces" section/"folder".

But if I make Point a type instead of an interface;

/**
 * document Point here
 */
export type Point = ReadOnly<{
  /**
   * document x here
   */ 
  x: number;
  /**
   * document x here
   */ 
  y: number;
}>;

...TypeDoc does not place Point under a "Types" section in the output but rather "ignores" it so you can only find it under "Modules". Also, by using ReadOnly the type is very verbose, but I suppose that's just how it works.

You can see this in action at VisionCamera documentation, where there is an "Interfaces" section on the left but no "Types" (or "Unions" or whatever) section. Instead, CameraPosition can only be found under "Modules" > "CameraPosition".

Suggested Solution

Add a "Types" output category just like "Interfaces", and allow individual union types to be documented.

@tgreyuk
Copy link
Member

tgreyuk commented Mar 18, 2021

This is not something this plugin can control and in any case it is not currently achievable. There are noises that it may be possible in the future. These references should provide further background:

@mrousavy
Copy link
Contributor Author

Oh I see, thanks 👍

@tgreyuk
Copy link
Member

tgreyuk commented Jun 15, 2021

Closing as duplicate of TypeStrong/typedoc#1540.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants