Skip to content

Extract to Constant Adds Unnecessary Parentheses around Assertions #42160

@DanielRosenwasser

Description

@DanielRosenwasser
let yadda = document.getElementById("asd")!;
let badda = document.getElementById("asd") as HTMLElement;
let bing  = <HTMLElement>document.getElementById("asd");

Try extracting the complete initializers of yadda, badda, and bing.

Each will create a new local variable, but will be unnecessarily parenthesized.

const newLocal = (document.getElementById("asd")!);
let yadda = newLocal;
const newLocal_1 = (document.getElementById("asd") as HTMLElement);
let badda = newLocal_1;
const newLocal_2 = (<HTMLElement>document.getElementById("asd"));
let bing  = newLocal_2;

The expected behavior is to not add these parentheses

const newLocal = document.getElementById("asd")!;
let yadda = newLocal;
const newLocal_1 = document.getElementById("asd") as HTMLElement;
let badda = newLocal_1;
const newLocal_2 = <HTMLElement>document.getElementById("asd");
let bing  = newLocal_2;

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: LS: Refactoringse.g. extract to constant or function, rename symbolEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".FixedA PR has been merged for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions