Typescript: JSDoc support for destructured parameters

Created on 26 Oct 2016  路  3Comments  路  Source: microsoft/TypeScript

TypeScript Version: 2.0.3

Code

interface Foo {
    /**
     * A bar value
     */
    bar?: string;
}

/**
 * A function
 *
 * @param foo A param
 * @param { bar } Another param
 * @param bar Another param
 */
function foo(foo: string, { bar }: Foo): void {
    bar;
    foo;
}

foo('bar', { bar: 'play' });

Expected behavior:

Intellisense for the second argument, or the second argument properties.

Actual behavior:

No way of providing a description for the destructured elements of a destructured parameter.

destructured

JSDoc In Discussion Suggestion VS Code Tracked help wanted

Most helpful comment

This does not work on version 1.21.1

/** Class representing a user. */
module.exports = class User {
  /**
  * Create a User.
  * @param {object} user
  * @param {string} user.id - The user id in uuid format
  * @param {string} user.name - The user name
  * @param {string} user.email - The user email
  * @param {string} user.password - The user password
  */
  constructor({id, name, email, password}) {
    this.id = id
    this.name = name
    this.email = email
    this.password = password
  }
}

All 3 comments

+1
As a JS developer relying on destructuring for function parameters, this issue generates a lot of false "problems" when mixing parameters with and without default values.

This does not work on version 1.21.1

/** Class representing a user. */
module.exports = class User {
  /**
  * Create a User.
  * @param {object} user
  * @param {string} user.id - The user id in uuid format
  * @param {string} user.name - The user name
  * @param {string} user.email - The user email
  * @param {string} user.password - The user password
  */
  constructor({id, name, email, password}) {
    this.id = id
    this.name = name
    this.email = email
    this.password = password
  }
}

Also an issue when functions return an interface

interface Returns {
  /** This object contains a getter that returns itself */
  get: (key: string) => string;
}

const buildObject = (): Returns => ({
  get: key => key
})

// shows jsdoc description when hovering over "obj1.get"
const obj1 = buildObject();
const a = obj1.get("key")

// Only shows signature "const get: (key: string) => string"
const {get} = buildObject();
const b = get("key");
Was this page helpful?
0 / 5 - 0 ratings

Related issues

uber5001 picture uber5001  路  3Comments

wmaurer picture wmaurer  路  3Comments

manekinekko picture manekinekko  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments

weswigham picture weswigham  路  3Comments