Typedoc: Render custom output name instead of "__namedParameters" for destructuring params

Created on 15 Jun 2020  路  3Comments  路  Source: TypeStrong/typedoc

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!

plugin idea

Most helpful comment

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.

All 3 comments

Is looks like __namedParameters is hardcoded in one place:

https://github.com/TypeStrong/typedoc/blob/d18664d86e85726a725a33e045090cc971d08d65/src/lib/converter/factories/parameter.ts#L31

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.

--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)

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

0815fox picture 0815fox  路  3Comments

atomsoftwarestudios picture atomsoftwarestudios  路  4Comments

ShadowManu picture ShadowManu  路  4Comments

topherfangio picture topherfangio  路  3Comments

KevinEady picture KevinEady  路  3Comments