Highmastdon
Highmastdon

Reputation: 7530

How to rename/refactor variable in VSCode without getting alias `oldName as newName`

VSCode has an option to change/rename variables called editor.action.rename, usually bound to F2.

However, in Typescript and Javascript, this uses aliases when renaming an imported variable, eg:

import { originalName } from 'my-package'

results in

import { originalName as newName } from 'my-package'

How to prevent this, and propagate the change to all references?

Upvotes: 27

Views: 3977

Answers (1)

Highmastdon
Highmastdon

Reputation: 7530

It is possible to prevent renaming using aliases:

  • open your settings file (JSON): CMD+SHIFT+P and select Preferences: Open Settings (JSON)
  • add the following lines
    "javascript.preferences.useAliasesForRenames": false,
    "typescript.preferences.useAliasesForRenames": false,
    

Upvotes: 37

Related Questions