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

Render all members of an intersection type #1021

Closed
1 task
jeremymeng opened this issue Apr 22, 2019 · 6 comments
Closed
1 task

Render all members of an intersection type #1021

jeremymeng opened this issue Apr 22, 2019 · 6 comments
Labels
enhancement Improved functionality plugin idea This feature may be best suited for a plugin

Comments

@jeremymeng
Copy link

Problem

When look at a type I would like to know what's available. For interface/class/etc. I can see their members. It would be great if I can see the members of an intersection type as well in one place. Currently I have to click on each type to view members of each type.

image

Suggested Solution

Some way to show the expanded member list for a intersection type at its doc so I don't have to do extra clicks to see its members.

@MrTelanie
Copy link

currently i am playing around a similar problem.
I want to use that type aliases for multiple function outlines.

I found out you can have multiple keys of same kind in an object.

/* eslint-disable no-dupe-keys */
export const Test = {
  test: (a, b) => 1,
  test: (a, b, c) => 1,
};

With that typedoc behaves like using function overload.

Currently on this i could not export functions directly. After searching for crazy valid characters of names, i found lots funny chars.
Valid JavaScript variable names in ES5 · Mathias Bynens

now i use \u02D0 (looks like ː) but you also could use \u200C as invisible char, but its invisible and confussing in your IDE too :D.

/**
 * @typedef {(alg: Alg) => PointType} PointAlg
 * @typedef {(x: number , y: number) => PointType} PointCon
 * @typedef {PointAlg & PointCon} point
 * @type {point}
 * @hidden
 */
export function point(x, y) {
  return pointFactory(x, y);
}

/**
 * @type {PointCon}
 */
export function point\u02D0(x, y) {
  return pointFactory(x, y);
}

/**
 * @type {PointAlg}
 */
export function point\u02D0\u02D0(alg) {
  return pointFactory(alg);
}

Now i get two entries in the create docs.

image

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Aug 14, 2019

@MrTelanie that is... horrible. I think your issue, and the original request, would be better off with a custom theme.


Rendering all elements of an intersection could quickly become incredibly large, a custom theme to handle this doesn't seem like a bad idea, but rendering everything by default would be problematic.

type Z = HTMLElement & File // => Huge number of properties

@MrTelanie
Copy link

until now i thought a custom theme is only for design. i will have a look for that.

Thanks to @Gerrit0

@Gerrit0 Gerrit0 added enhancement Improved functionality plugin idea This feature may be best suited for a plugin labels Jan 12, 2020
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jan 12, 2020

Marking this as a plugin idea as I think it can be achieved with a plugin cleanly. I might give this a shot eventually, but there are higher priority issues. My idea is that you should be able to annotate a type with @inline, and the plugin will find references to that type and replace it with the contents of that type.

This removes the problem where rendering all elements of an intersection could explode in complexity.

@VanTanev
Copy link

@Gerrit0 Can you give some guidance as to how I could approach writing this plugin? I do need this feature, and if it's not too complex I can try to write it.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jun 28, 2020

Here's how I would approach this.

  1. Create a plugin which listens to Converter.EVENT_CREATE_DECLARATION, checks if the reflection is a type alias and has an @inline comment, and add it to a saved array.
  2. Also listen to Converter.EVENT_RESOLVE. This happens after EVENT_CREATE_DECLARATION. At this point, you can check the types on the reflection to find reference types which refer to a type in your saved array of inline variables and replace them with the cloned type. https://github.com/socsieng/typedoc-plugin-typescript-declaration/blob/54de68eb2a02264e22bb47d833d5f1e246244039/src/convert/unresolved-types-mapper.ts does something similar.

It would be really nice to have a transformer API that can eliminate the traversal logic... I've opened #1325 as a place to discuss that and hopefully come up with something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improved functionality plugin idea This feature may be best suited for a plugin
Projects
None yet
Development

No branches or pull requests

4 participants