Skip to content

Codefix convertTypedefToType creates types in a wrong place #55308

Open
@egorio

Description

@egorio

Currently "typedef to type conversion" doesn't care about the place where type is generated, resulting broken code if the type if generated inside the class / interface etc.

It's better to generate class in closest SourceFile root, namespace root or even function body in case the comment containing @typedef is placed at any other place of the code.

🔎 Search Terms

Searched for typedef issues reported after March 1st

🕗 Version & Regression Information

  • This changed between versions 5.1.x and latest

⏯ Playground Link

Link to play

💻 Code

class Example {
  /**
   * List of items to be rendered in the bar chart
   * @typedef {{ count: number }} Counter
   * @returns {Counter}
   */
  get something() {
    return { count: 0 };
  }
}

🙁 Actual behavior

class Example {
  type Counter={ count: number; };     // <- bug is here
  get something() {
    return { count: 0 };
  }
}

🙂 Expected behavior

type Counter={ count: number; };

class Example {
  /**
   * List of items to be rendered in the bar chart
   * @returns {Counter}
   */
  get something() {
    return { count: 0 };
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Refactoringse.g. extract to constant or function, rename symbolEffort: CasualGood issue if you're already used to contributing to the codebase. Harder than "good first issue".Help WantedYou can do thisRescheduledThis issue was previously scheduled to an earlier milestone

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions