microsoft / microsoft/TypeScript

Preserve properties descriptions when converting @typedef's to interfaces

Open
#54,716 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Experience Enhancement Help Wanted Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

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

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

Start with the convertTypedefToType codefix and the mentioned test case, tests/cases/fourslash/codeFixConvertTypedefToType3.ts. Trace how @typedef and @property descriptions are read during conversion, then update the test so it verifies that type and property descriptions appear as interface JSDoc comments.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
devtools
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.