Replace with existing variable

Replace an expression with an existing variable.

Replace with existing variable

What do I need to consider?

Could change type

This refactoring can lead to type errors (not runtime errors) when the type on the declared variable is wider than the type of the replaced expression, and the replaced expression is used in ways that require the narrower type. Here is an example:

function doSomething(aParameter: "123") {
  // ...
}

const aVariable: string = "123";
doSomething("123"); // replacing with aVariable changes type

Configuration

Related Code Assists

Learn More

Available In