Skip to content

Commit c3a2557

Browse files
authored
fix(lint): lint/suspicous/noRedeclare should not report redeclarations for infer type in conditional types (#8417)
1 parent 250b519 commit c3a2557

5 files changed

Lines changed: 28 additions & 2 deletions

File tree

.changeset/breezy-groups-hope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#7809](https://github.com/biomejs/biome/issues/7809): [`noRedeclare`](https://biomejs.dev/linter/rules/no-redeclare/) no longer reports redeclarations for `infer` type in conditional types.

crates/biome_js_analyze/src/lint/suspicious/no_redeclare.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,14 @@ fn check_redeclarations_in_single_scope(scope: &Scope, redeclarations: &mut Vec<
171171
// A parameter can override a previous parameter.
172172
// - when both are type parameter in different declarations.
173173
// A type parameter can be redeclared if they are in different declarations.
174+
// - when both are infer types.
175+
// An infer type can be redeclared in the same conditional type.
174176
if !(first_decl.is_mergeable(&decl)
175177
|| first_decl.is_parameter_like() && decl.is_parameter_like()
176178
|| first_decl.is_type_parameter()
177179
&& decl.is_type_parameter()
178-
&& first_decl.syntax().parent() != decl.syntax().parent())
180+
&& first_decl.syntax().parent() != decl.syntax().parent()
181+
|| first_decl.is_infer_type() && decl.is_infer_type())
179182
{
180183
redeclarations.push(Redeclaration {
181184
name: name.text().into(),
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
/* should not generate diagnostics */
22
// Issue https://github.com/biomejs/biome/issues/2659
3-
type Test<T> = T extends Array<infer U> ? true : false
3+
type Test<T> = T extends Array<infer U> ? true : false
4+
5+
type TestMultipleInfer<T extends readonly string[]> = T[number] extends
6+
| `-${infer Base}`
7+
| infer Base
8+
? Base
9+
: never

crates/biome_js_analyze/tests/specs/suspicious/noRedeclare/valid-conditional-type.ts.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@ expression: valid-conditional-type.ts
77
/* should not generate diagnostics */
88
// Issue https://github.com/biomejs/biome/issues/2659
99
type Test<T> = T extends Array<infer U> ? true : false
10+
11+
type TestMultipleInfer<T extends readonly string[]> = T[number] extends
12+
| `-${infer Base}`
13+
| infer Base
14+
? Base
15+
: never
16+
1017
```

crates/biome_js_syntax/src/binding_ext.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ impl AnyJsBindingDeclaration {
199199
matches!(self, Self::TsTypeParameter(_))
200200
}
201201

202+
/// Returns `true` if `self` is an infer type.
203+
pub const fn is_infer_type(&self) -> bool {
204+
matches!(self, Self::TsInferType(_))
205+
}
206+
202207
/// Returns the export statement if this declaration is directly exported.
203208
pub fn export(&self) -> Option<JsExport> {
204209
let maybe_export = match self {

0 commit comments

Comments
 (0)