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

TypeScript Getters and Setters do not render correctly with TypeDoc #882

Closed
ltfschoen opened this issue Oct 10, 2018 · 2 comments
Closed
Labels
bug Functionality does not match expectation

Comments

@ltfschoen
Copy link

ltfschoen commented Oct 10, 2018

In our codebase, we are using TypeDoc to generate a Gitbook. In the development environment, using that codebase we can preview the Gitbook generated by TypeDoc by installing relevant dependencies, building and serving the Gitbook with yarn; yarn run build; yarn gitbook serve and then viewing the Gitbook at http://localhost:4000. The production version of the GitBook is at published at https://polkadot.js.org/api/.

We encountered an issue, whereby if we apply TypeDoc to TypeScript Getters get and Setters set, TypeDoc doesn't appear to correctly recognise them and so does not render them correctly in the generated Gitbook pages.

For example, in the following code snippet we define a Getter with get provider () that returns the value of _provider:

export default class Rpc implements RpcInterface {
  private _provider: ProviderInterface;

  constructor (provider: ProviderInterface) {
    this._provider = provider;
  }

  /**
   * @example
   * <BR>
   *
   * ```javascript
   * <insert_example_here>
   * ```
   */
  get provider (): ProviderInterface { return this._provider; }
...

However in Gitbook page it, whilst it correctly lists it under the heading "Accessors", it renders it as getprovider() instead
of get provider() (i.e. there's no space between, so it doesn't appear to be recognising the Getter correctly). See screenshot below:

screen shot 2018-10-10 at 12 04 40

So this is a problem because a user reading the the Gitbook documentation may think the method name is getprovider() when it's actually just provider()

We are using:

  • TypeScript 3.0.1
  • TypeDoc 0.12.0
@aciccarello aciccarello added the bug Functionality does not match expectation label Oct 10, 2018
@ltfschoen
Copy link
Author

ltfschoen commented Oct 14, 2018

I tried looking into this issue myself. I looked through the Typedoc codebase to find where getters and setters are processed, and then added console.log's in the relevant parts of the JavaScript files of the node_modules/typedoc dependency in our codebase before building the Gitbook.

I found where it generates the method name of the getter on Line 172 of lib/models/reflections/declaration.ts and setter on Line 176 of lib/models/reflections/declaration.ts, and tried prepending a blank space in front of it. But it didn't render the blank space so somewhere else in the codebase trims the whitespace from the method name.
I tried using \u00A0 instead of just but it still didn't render. But when I prepended a letter accompanied before the space P it rendered and I could see what was being affected. See the rendered output and associated code changes below:
screen shot 2018-10-14 at 01 43 54
screen shot 2018-10-14 at 01 47 16

It would be more ideal to just add a blank space after the get and set , since prepending the blank space before the method name instead causes the blank space to appear with the method name everywhere else that the method name is rendered (as shown in the screenshot).

Note: This is another spot with getters and setters being generated somehow https://github.com/TypeStrong/typedoc/blob/master/src/lib/converter/nodes/accessor.ts#L30

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Nov 13, 2019

image

It seems this was fixed, it doesn't show up in 0.15.x, please reopen if it is still broken for you.

@Gerrit0 Gerrit0 closed this as completed Nov 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Functionality does not match expectation
Projects
None yet
Development

No branches or pull requests

3 participants