Skip to content

"TS6133: xxx is declared but its value is never read." behaviour #37137

Closed
@WesleyYue

Description

@WesleyYue

TypeScript Version: 3.8.3

Search Terms:
"is declared but its value is never read."
Code

interface A {
  one: string;
  two: string;
}

class B {
  private _aa: A;
  constructor() {
    this._aa = { one: "one", two: "two" };
    on(Callback);

    function on(cb: ()=>void) {
      cb();
    }
    function Callback() {
      console.log(this._aa.one);
    }
  }
}

new B();

Expected behavior:
I would expect to not get the error below since the _aa variable is used implicitly by reading _aa.one
Actual behavior:
When compiling, I get the following error: TS6133: '_aa' is declared but its value is never read.

Related Issues:
#19700 which leads to https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#write-only-references-are-unused but this is not the same issue. The variable in question should be read via reading one of its subfields.

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