Microsoft/TypeScript
Vedi su GitHubClass marked as unused when used in a static block
Open
#57.620 aperta il 3 mar 2024
BugDomain: LS: Suggestion DiagnosticsHelp Wanted
Metriche repository
- Star
- (48.455 star)
- Metriche merge PR
- (Merge medio 6g 17h) (9 PR mergiate in 30 g)
Descrizione
🔎 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