diff --git a/.changeset/fix-construct-signature-unused-type-param.md b/.changeset/fix-construct-signature-unused-type-param.md new file mode 100644 index 000000000000..e213d9709d4c --- /dev/null +++ b/.changeset/fix-construct-signature-unused-type-param.md @@ -0,0 +1,5 @@ +--- +"@biomejs/biome": patch +--- + +Fix [#8435](https://github.com/biomejs/biome/issues/8435): resolved false positive in `noUnusedVariables` for generic type parameters in construct signature type members (`new (): T`). diff --git a/crates/biome_js_analyze/tests/specs/correctness/noUnusedVariables/validInterface.ts b/crates/biome_js_analyze/tests/specs/correctness/noUnusedVariables/validInterface.ts index 85539f091aca..fd311ec0ac85 100644 --- a/crates/biome_js_analyze/tests/specs/correctness/noUnusedVariables/validInterface.ts +++ b/crates/biome_js_analyze/tests/specs/correctness/noUnusedVariables/validInterface.ts @@ -1,15 +1,30 @@ /* should not generate diagnostics */ interface A { - f(a: number); - set a(a: number); - [key: string]: string; + f(a: number); + set a(a: number); + [key: string]: string; +} + +// Construct signature type members with generic parameters +export interface Constructor { + new (): T; + new (value: T): T; +} + +export interface ConstructorWithMultipleOverloads { + new (): T; + (): T; } class B implements A { - f(a: number) {console.log(a)} - set a(a: number) {console.log(a)} - [key: string]: string; + f(a: number) { + console.log(a); + } + set a(a: number) { + console.log(a); + } + [key: string]: string; } console.log(new B()); diff --git a/crates/biome_js_analyze/tests/specs/correctness/noUnusedVariables/validInterface.ts.snap b/crates/biome_js_analyze/tests/specs/correctness/noUnusedVariables/validInterface.ts.snap index e13eb25c2453..fa25dc1b90f3 100644 --- a/crates/biome_js_analyze/tests/specs/correctness/noUnusedVariables/validInterface.ts.snap +++ b/crates/biome_js_analyze/tests/specs/correctness/noUnusedVariables/validInterface.ts.snap @@ -7,19 +7,32 @@ expression: validInterface.ts /* should not generate diagnostics */ interface A { - f(a: number); - set a(a: number); - [key: string]: string; + f(a: number); + set a(a: number); + [key: string]: string; +} + +// Construct signature type members with generic parameters +export interface Constructor { + new (): T; + new (value: T): T; +} + +export interface ConstructorWithMultipleOverloads { + new (): T; + (): T; } class B implements A { - f(a: number) {console.log(a)} - set a(a: number) {console.log(a)} - [key: string]: string; + f(a: number) { + console.log(a); + } + set a(a: number) { + console.log(a); + } + [key: string]: string; } console.log(new B()); ``` - - diff --git a/crates/biome_js_semantic/src/events.rs b/crates/biome_js_semantic/src/events.rs index 0b6e01707531..398b178ced2d 100644 --- a/crates/biome_js_semantic/src/events.rs +++ b/crates/biome_js_semantic/src/events.rs @@ -461,6 +461,7 @@ impl SemanticEventExtractor { | TS_DECLARE_FUNCTION_DECLARATION | TS_DECLARE_FUNCTION_EXPORT_DEFAULT_DECLARATION | TS_CALL_SIGNATURE_TYPE_MEMBER + | TS_CONSTRUCT_SIGNATURE_TYPE_MEMBER | TS_METHOD_SIGNATURE_CLASS_MEMBER | TS_METHOD_SIGNATURE_TYPE_MEMBER | TS_INDEX_SIGNATURE_CLASS_MEMBER @@ -866,6 +867,7 @@ impl SemanticEventExtractor { | TS_DECLARE_FUNCTION_DECLARATION | TS_DECLARE_FUNCTION_EXPORT_DEFAULT_DECLARATION | TS_CALL_SIGNATURE_TYPE_MEMBER + | TS_CONSTRUCT_SIGNATURE_TYPE_MEMBER | TS_METHOD_SIGNATURE_CLASS_MEMBER | TS_METHOD_SIGNATURE_TYPE_MEMBER | TS_INDEX_SIGNATURE_CLASS_MEMBER