Skip to content

Improve rendering of unions of object literals #2554

@xuhdev

Description

@xuhdev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions