Microsoft/TypeScript
GitHub ã§èŠãClass marked as unused when used in a static block
Open
#57,620 opened on 2024幎3æ3æ¥
BugDomain: LS: Suggestion DiagnosticsHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð 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