Skip to content

'var' is declared but its value is never read false-positive #51951

@boris-petrov

Description

@boris-petrov

Bug Report

🔎 Search Terms

Nullish coalescing assignment
declared but its value is never read

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Nullish coalescing assignment

⏯ Playground Link

Playground link with relevant code

💻 Code

class A {
  private x?: number;

  public foo(): void {
    this.x ??= setTimeout(() => {});
  }
}

🙁 Actual behavior

There is an error that 'x' is declared but its value is never read which is not true because ??= reads and then writes the value.

🙂 Expected behavior

No error on x.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions