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

Automatically inline types that are not exported #1823

Closed
jugglingcats opened this issue Dec 14, 2021 · 2 comments
Closed

Automatically inline types that are not exported #1823

jugglingcats opened this issue Dec 14, 2021 · 2 comments
Labels
enhancement Improved functionality plugin idea This feature may be best suited for a plugin wontfix Declining to implement

Comments

@jugglingcats
Copy link

Search Terms

inline types

Problem

At the moment if a type is not exported, just the name of the type is included in the typedoc JSON output, effectively making the type opaque.

Suggested Solution

It would be great if typedoc could simply inline these types. I have read #1021 (and related issues) and this request also seems related but perhaps suggests a sensible default behaviour. After all if the type is included the exported interface but not exported itself, it is reasonable to see the members in the generated docs. The behaviour could be behind an option if it could causes issues on some projects.

Apologies if this has been discussed already.

@jugglingcats jugglingcats added the enhancement Improved functionality label Dec 14, 2021
@jugglingcats
Copy link
Author

I also looked at #1657 and typedoc-plugin-missing-exports. In our case we don't want these types included as named types at all. They are convenience types which are an internal detail of our project and not for public consumption. For example:

type DigitalOutputCommand = {
    /** the desired value */
    setValue: boolean
    /** whether this state should override state set by an activity */
    override: boolean
}

type DigitalOutputStatus = {
   /** the effective value determined by the system */
    effectiveValue: boolean
} & DigitalOutputCommand

Including these as full types simply makes navigating the documentation much more cumbersome...

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jan 3, 2022

You could probably write a plugin to (mostly...) do this (it would look fairly similar to the missing-exports one, just calling convertType instead of convertSymbol, might be a good option for that plugin...). But it'll die a horrible death as soon as any recursive types show up.

type Rec = { rec: Rec }
export type Foo = { foo: true } & Rec // = { foo: true } & { rec: { rec: { rec: { rec: ...

It is still my opinion that libraries ought to be written to make the user's life easier. I would make those types interfaces (so they get their own pages, giving each type its own page is something I want to experiment with someday), and export them. Telling a user that a type that is effectively visible isn't meant to be touched is annoying.

let y: OopsCantImportFromYourLib
try {
  mightFail()
  y = getY()
  mightFail2(y) // can't define this function as using the proper type either
} catch (err) {
  if (y) {
   reportNonFatalFailure(y)
  } else {
    throw err
  }
}

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 wontfix Declining to implement
Projects
None yet
Development

No branches or pull requests

2 participants