Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
blickly opened this issue Jan 17, 2025 · 0 comments

Comments

@blickly
Copy link
Contributor

blickly commented Jan 17, 2025

πŸ”Ž 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant