Microsoft/TypeScript
Auf GitHub ansehenClass marked as unused when used in a static block
Open
#57.620 geöffnet am 3. März 2024
BugDomain: LS: Suggestion DiagnosticsHelp Wanted
Repository-Metriken
- Stars
- (48.455 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)
Beschreibung
🔎 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