Skip to content

Destructured parameters: flag.isOptional and reference types not working #957

@xAlien95

Description

@xAlien95

Expected Behavior

I'm using the command:

typedoc src --json exported.json --target es6

I expect the two arrow functions createAlarm and createAlarm2 to have the same json output (except for __namedParameters of course).

Actual Behavior

For createAlarm, Typedoc doesn't set the .isOptional flag to each parameter and outputs different types (e.g. repeat parameter type.elementType is directly an union instead of a reference, active parameter type contains true and false instead of boolean):

users_xalien95_desktop_typedoc_docs_modules__index html 1

Steps to reproduce the bug

Run Typedoc on the following code:

type Frequency = (
  'Sunday'
  | 'Monday'
  | 'Tuesday'
  | 'Wednesday'
  | 'Thursday'
  | 'Friday'
  | 'Saturday'
);

type Switch = (
  'ON'
  | 'OFF'
);

/**
 * With destructured parameter
 *
 * - handles default values
 * - flag.isOptional not working
 * - reference type not working
 */
const createAlarm = (
  {
    /** The alarm active state */
    active = true,
    /** The alarm time */
    time = '',
    /** Whether the alarm should repeat on certain days */
    repeat = [],
  }: {
    active?: boolean | Switch,
    time?: string,
    repeat?: Frequency[],
  },
): string => `Alarm at ${time} every ${repeat.join(', ')} is ${active}`;

/**
 * Without destructured parameter
 *
 * - doesn't handle default values
 * - flag.isOptional works
 * - reference type works
 */
const createAlarm2 = (
  options: {
    /** The alarm active state */
    active?: boolean | Switch,
    /** The alarm time */
    time?: string,
    /** Whether the alarm should repeat on certain days */
    repeat?: Frequency[],
  },
): string => {
  const {
    active = true,
    time = '',
    repeat = [],
  } = options;

  return `Alarm at ${time} every ${repeat.join(', ')} is ${active}`;
};

Environment

  • Typedoc version: 0.14.2
  • TypeScript version: 3.2.4
  • Node.js version: v10.13.0
  • OS: macOS 10.14.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions