Why does typescript report that the variable is not used even though it is referenced inside
"noUnusedLocals": true, <-- This line
Typescript is complaining that you never read the variable. Your
_close method only sets it. And I think typescript rightly complains, as what's the point of a storing something if you are never interested in using it's value later?
Moreover, the error goes away if you remove the
private modifier because then the value can be read by anyone who has an instance of the class. So typescript can no longer verify that the value is never read (since it might be used by others). But with
private, it knows only the class methods can access it, so if it doesn't see the value get read anywhere within the class itself, it will produce an error.