Skip to content

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

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

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

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

mrousavy opened this issue Mar 18, 2021 · 2 comments

Comments

@mrousavy
Copy link

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;
}

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".

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.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Mar 21, 2021

Can't document union types

This is the "union enums" request - microsoft/tsdoc#164. I plan to get around to this eventually, but haven't gotten to it yet... there's another change I want to make to how type aliases are resolved in 0.21, so this will probably happen then.

No "types" category in output

This looks like a problem with your theme to me. The default theme includes a "Type Aliases" section. https://typedoc.org/api/modules.html

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Oct 18, 2021

Going to track the union-enums under #1710, since it's more easily searchable. The other issue seems to be a problem with your theme, not TypeDoc.

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