TypeScript: Class marked as unused when used in a static block
π Search Terms
class unused static field block
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
let BluethootDevice_create;
class BluethootDevice {
#id!: string;
static #allowConstruct = false;
private constructor() {
if (!BluethootDevice.#allowConstruct) {
throw new Error("You cannot instantiate this class directly");
}
}
static {
BluethootDevice_create = (id: string) => {
BluethootDevice.#allowConstruct = true;
const device = new BluethootDevice();
BluethootDevice.#allowConstruct = false;
device.#id = id;
return device;
};
}
get id() {
return this.#id;
}
}
let a = 2;
BluethootDevice_create("aa");
export {}
π Actual behavior
The class BluethootDevice is marked as unused, but itβs used by the BluethootDevice_create function
π Expected behavior
BluethootDevice should not be marked as unused
Additional information about the issue
No response
About this issue
- Original URL
- State: open
- Created 4 months ago
- Comments: 15 (5 by maintainers)
β
staticblock is IIFEβ feels like the right view of this, since it runs on block evaluation rather than on first constructor call.