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 custom output name instead of "__namedParameters" for destructuring params #1321

Closed
pushkov-fedor opened this issue Jun 15, 2020 · 4 comments
Labels
plugin idea This feature may be best suited for a plugin

Comments

@pushkov-fedor
Copy link

Hi everyone! I work on project that contains both TypeScript and JavaScript files. I use TypeDoc for generating documentation. It works awesome, but i would like to know: is there a way to replace default "__namedParameters" output for something else (e.g. "options")?

Screenshot from 2020-06-15 15-55-03

Thank you!

@pushkov-fedor pushkov-fedor changed the title Render output as "options" instead of "__namedParameters" for destructuring params Render custom output name instead of "__namedParameters" for destructuring params Jun 15, 2020
@raineorshine
Copy link

Is looks like __namedParameters is hardcoded in one place:

parameter.name = '__namedParameters';

Perhaps an option like --namedParametersName could be added to set the display name? Then, correct me if I'm wrong, this would be accessible as converter.namedParametersName within createParameter? Happy to submit a PR with some help if desired.

@Gerrit0
Copy link
Collaborator

Gerrit0 commented Jun 19, 2020

--namedParametersName

I don't particularly care for this, or the existing implementation... Right now TypeDoc does bad things if you destructure more than one argument. I'd rather switch to generating arg_# like the language service does

type Foo = [1, 2, 3]
declare const x: (...arg: Foo) => string
// hover      ^

That said, a plugin which makes this change is pretty easy to write (untested)

const { Converter } = require('typedoc')
export function load({ application }) {
  application.converter.on(Converter.EVENT_CREATE_PARAMETER, param => {
    if (param.name === '__namedParameters') param.name = 'options'
  })
}

@cherryblossom000
Copy link

cherryblossom000 commented Jun 24, 2020

A plugin that works:

import {Converter} from 'typedoc/dist/lib/converter'
import type {ParameterReflection} from 'typedoc'
import type {Context} from 'typedoc/dist/lib/converter'
import type {PluginHost} from 'typedoc/dist/lib/utils'

export function load({application}: PluginHost) {
  application.converter.on(Converter.EVENT_CREATE_PARAMETER, (_: Context, param: ParameterReflection) => {
    if (param.name === '__namedParameters') param.name = 'options'
  })
}

Edit: I created a plugin that does exactly this.

@Gerrit0 Gerrit0 added the plugin idea This feature may be best suited for a plugin label Nov 28, 2020
@Gerrit0 Gerrit0 closed this as completed Nov 28, 2020
@cherryblossom000
Copy link

Thanks to #1704, the name of a destructured parameter is inferred by the @param tag and my plugin is no longer necessary!

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

No branches or pull requests

4 participants