p42ai / js-assistant

120+ refactorings and code-assists for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=p42ai.refactor
MIT License
125 stars 8 forks source link

Remove braces from arrow function produces broken code when line includes cast #82

Open mprisehk opened 3 months ago

mprisehk commented 3 months ago

Minimal example:

type User = { id: number; name: string }

const userNames = ['Alice', 'Bob']

const users = userNames
  .filter(x => !!x)
  .map((userName, i) => {
    return { id: i, name: userName } as unknown as User
  })

Choose the 'Remove braces from arrow function' refactoring for the content of the 'map' function: image

Output: image

Expected output: image