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

Ability to handle union of object literals #2554

Open
xuhdev opened this issue Apr 25, 2024 · 1 comment
Open

Ability to handle union of object literals #2554

xuhdev opened this issue Apr 25, 2024 · 1 comment
Labels
enhancement Improved functionality

Comments

@xuhdev
Copy link
Contributor

xuhdev commented Apr 25, 2024

Search Terms

react component, union

Problem

When the param is a union of object literals, @param fails to document the property names. For example, typedoc would not output the doc after options.northPole and options.southPole.

/**
 * @param options - Magnet options.
 * @param options.northPole - The North Pole. Although optional, but must appear with South Pole.
 * @param options.southPole - The North Pole. Although optional, but must appear with North Pole.
 */
function Magnet({
  northPole,
  southPole,
}:
  | { northPole: number; southPole: number }
  | { northPole?: undefined; southPole?: undefined }) {}

Context

This is possible to encounter likely in a React component. One possible solution is to rewrite the above as overloads. However, depending on the context, it may not be desirable to do so. In fact, the ESLint typescript plugin has a rule "unified signatures" that disfavor splitting into overloads.

@xuhdev xuhdev added the enhancement Improved functionality label Apr 25, 2024
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Apr 27, 2024

This is... super ugly to actually implement. TypeDoc already copies comments to the reflections for both instances of northPole, so this would just be a rendering change... but it's a rendering change where you either have to just render every possible instance of the union (rendering comments multiple times) or somehow decide to just render one branch of the union... or go through every member of the union and just render each possible property once...

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

No branches or pull requests

2 participants