Skip to content

[isolatedDeclarations] Quick-fix for adding missing annotations can duplicate commentsΒ #60991

Open
@blickly

Description

@blickly

πŸ”Ž Search Terms

isolatedDeclarations, autofixer, quick fix, quickfixer, quick-fix, duplicate, redundant, comments

πŸ•— Version & Regression Information

TS5.5+

⏯ Playground Link

https://www.typescriptlang.org/play/?downlevelIteration=true&importHelpers=true&target=99&module=1&isolatedDeclarations=true&ts=5.7.3#code/KYDwDg9gTgLgBAMwK4DsDGMCWEWIBQCUcA3gFBwVxo4DO8EcAvHAPQBUbcARsAtMHDYsSrTphQAbcQMh0AtMUHCWw4CgAmcKShkR5ZSpRVx1ENEgC2a+AkxQ6cGAE8wwcodFxx2gTz5QBITgQT29pODAAuWoJHCU4AC5QyXDI4DlnV3iAVmSfCL0YDJdA4QAaVmEAQwQYYCgqCAsLKoBGd0NjU3MrFHgaYGoNRxKOow44ACZuXn54p0S4AHI6KCXRTmmauoahCpVt+sbmqsmximM06NiacQBzMYBfDbhD3ZYAbjGAmCQoXAgX0eQA

πŸ’» Code

export function f() {
    const o = /** before */ { /* inline post-{ */ // end line post-{
      // document first type
      /* inline before */ x /* inline pre-colon */ : /* inline pre-type */ 5 /* inline post-type */ , // after comma1
      // document second type
      /** 2 before */ y : 'str' /** 2 after */, //after comma2
      // pre-closing
    } /** after */;
    return o;
}

πŸ™ Actual behavior

After running the autofixer, the result includes many of the inline code comments in the added type annotation. It looks like:

export function f(): { /* inline post-{ */ // end line post-{
// document first type
/* inline before */ x: number; /* inline post-type */ // after comma1
// document second type
/** 2 before */ y: string; /** 2 after */
} {
    const o = /** before */ { /* inline post-{ */ // end line post-{
      // document first type
      /* inline before */ x /* inline pre-colon */ : /* inline pre-type */ 5 /* inline post-type */ , // after comma1
      // document second type
      /** 2 before */ y : 'str' /** 2 after */, //after comma2
      // pre-closing
    } /** after */;
    return o;
}

πŸ™‚ Expected behavior

The actual behavior isn't technically broken, but I would generally expect/prefer the generated annotation to include only types with no comments. Something like:

export function f(): {
    x: number;
    y: string;
} {
    const o = /** before */ { /* inline post-{ */ // end line post-{
      // document first type
      /* inline before */ x /* inline pre-colon */ : /* inline pre-type */ 5 /* inline post-type */ , // after comma1
      // document second type
      /** 2 before */ y : 'str' /** 2 after */, //after comma2
      // pre-closing
    } /** after */;
    return o;
}

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions