Typedoc: Support custom comments for function type literals

Created on 7 Mar 2019  路  2Comments  路  Source: TypeStrong/typedoc

Expected Behavior

Typedoc should properly interpret comments for the parameters and return type of function type literals.

Actual Behavior

Typedoc displays the parameters and return type for the function type literal, but the comments provided are incorrectly placed.

Steps to reproduce the bug

Given the following function type literal:

export type Validator = (value: any) => boolean;

Typedoc automatically generates the following documentation:

image

Adding comments to the type declaration:

/**
 * A validator function.
 * @param value The value to be validated.
 * @returns `true` if the value is valid.
 * @returns `false` if the value is invalid.
 */
export type Validator = (value: any) => boolean;

Results in the following incorrect documentation:

image

Environment

  • Typedoc version: v0.14.2
  • Node.js version: v10.15.0
  • OS: Windows 10
bug enhancement

Most helpful comment

Hey man, I have the same needs,after many attempts, I finally commented like this and succeeded

/**
 * commments for MyFunType
 */
type MyFunType = 
/**
 * @param title commonets for the title param
 * @param id comments for the id param
 * @returns comments for return value
 */
(title: string, id: number) => number;

The generated docs:
image

All 2 comments

Hey man, I have the same needs,after many attempts, I finally commented like this and succeeded

/**
 * commments for MyFunType
 */
type MyFunType = 
/**
 * @param title commonets for the title param
 * @param id comments for the id param
 * @returns comments for return value
 */
(title: string, id: number) => number;

The generated docs:
image

The syntax found by @fenyiwudian works great! But it took me some time and perseverance to find this issue. It would be great if this syntax was documented in the TypeDoc documentation.

Was this page helpful?
0 / 5 - 0 ratings