microsoft / microsoft/TypeScript

When generating declaration file from a JavaScript file with JSDoc, description of named parameters should be copied to description of the properties in the generated object type

Open
#57,269 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔍 Search Terms
  • copy description from jsdoc to properties
  • named parameter description
✅ Viability Checklist
⭐ Suggestion

Currently, the description that follows a @param options.field Description of field does not copy Description of field to the corresponding property in the generated object type. But TypeScript should've done that.

Related: https://github.com/microsoft/TypeScript/issues/57328

📃 Motivating Example

JavaScript file:

/**
 * Do something
 * @param {Object} options Description of options
 * @param {String} options.foo Description of foo
 * @param {Number} options.bar Description of bar
 */
export function doSomething(options) {
  console.log(options)
}

tsconfig:

{
  "compilerOptions": {
    "allowJs": true,
    "checkJs": true,
    "declaration": true,
    "emitDeclarationOnly": true,
    "strict": true,
    "strictNullChecks": true,
    "module": "ES2022",
    "target": "ES2022"
  }
}

Expected behavior:

/**
 * Do something
 * @param {Object} options Description of options
 * @param {String} options.foo Description of foo
 * @param {Number} options.bar Description of bar
 */
export function doSomething(options: {
    /** Description of foo **/
    foo: string;
    /** Description of bar **/
    bar: number;
}): void;

Actual behavior:

/**
 * Do something
 * @param {Object} options Description of options
 * @param {String} options.foo Description of foo
 * @param {Number} options.bar Description of bar
 */
export function doSomething(options: {
    foo: string;
    bar: number;
}): void;
💻 Use Cases
  1. What do you want to use this for? Generate TypeScript declarations with working intellisense
  2. What shortcomings exist with current approaches? Intellisense ignores descriptions of named parameter
  3. What workarounds are you using in the meantime? None

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the JavaScript example and tsconfig shown in the report, then trace TypeScript's JSDoc handling during declaration emission; no source files or tests are named in the payload. Done means generated declarations retain the descriptions for foo and bar as property comments and a regression test covers the case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.