Microsoft/TypeScript

Preserve properties descriptions when converting @typedef's to interfaces

開放

#54,716 建立於 2023年6月20日

 (0 則留言) (1 個反應) (0 位負責人)TypeScript (13,395 個分叉)batch import
Experience EnhancementHelp WantedSuggestion

倉庫指標

星標
 (108,860 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Suggestion

Codefix convertTypedefToType doesn't preserve type and property descriptions.

For example in the test case properties id, name, and age have descriptions, but they are dropped when codefix is applied.

Suggest to preserve that description after converting @typedef to interface as properties descriptions like /** description */

🔍 Search Terms

Searched for typedef issues reported after March 1st

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Preserve @property description after converting @typedef to interfaces (as /** description */)

📃 Motivating Example

Converting

 /**
  * @typedef Foo
  * type {object}
  * @property {string} id - person's ID
  * @property name {string} // person's name
  * @property {number|undefined} age - person's age
  */

to

interface Foo {
    /** person's ID */
    id: string;
    
    /** person's name */
    name: string;
    
    /** person's age */
    age: number | undefined;
}

instead of

interface Foo {
    id: string;
    name: string;
    age: number | undefined;
}

💻 Use Cases

Applying suggested codefix in IDEs

### Tasks

貢獻者指南