documentationjs / documentation

:book: documentation for modern JavaScript
http://documentation.js.org/
Other
5.78k stars 482 forks source link

Proper usage with Typescript #1605

Open balanza opened 1 year ago

balanza commented 1 year ago

Version 14.0.2

Hi,

I'm working with Typescript and I'm wondering which is the proper way to deal with type specifications. Let me propose an example to better explain myself.

Example

The code below can also be found as a working example here: https://codesandbox.io/p/sandbox/nice-cloud-3rxyg8

Suppose the following code:

// index.ts
type Address = { street: string; city: string };
type Email = { email: string };
type Phone = { phone: string };

/**
 * My User lorem ipsum
 */
export type User = {
  name: string;
  address: Address;
  contacts: Email & Phone;
};

/**
 * An example of person lorem ipsum
 */
export interface Person {
  name: string;
  surname: string;
  address: Address;
}

and suppose the following command:

$ documentation readme src/index.ts --parse-extension ts  --section=API

I receive the following output (in my README.md file):

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

*   [User](#user)
    *   [Properties](#properties)
*   [Person](#person)

### User

My User lorem ipsum

Type: {name: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), address: Address, contacts: any}

#### Properties

*   `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
*   `address` **Address**&#x20;
*   `contacts` **any**&#x20;

### Person

An example of person

Expectations

I spotted some issues in the outcome. I don't know if they are because of a misuse by myself, a known bug, a missing feature, or a feature documentation.js won't support at all. I read the docs and I found no clues about the will to support Typescript types and any known issues.

  1. Person members aren't listed just because it's written as an interface instead of a type
  2. User.address is of type Address, which is not meant to be exposed; Shouldn't it be expanded in the property definition?
  3. User.contacts isn't resolved because of the intersection &
  4. How can I add a description text for each property?

Apologize if any of these issues were already documented.