diff --git a/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs b/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs index 01ef56122dc70..24c6979c11c59 100644 --- a/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs +++ b/crates/oxc_linter/src/rules/typescript/consistent_indexed_object_style.rs @@ -1,6 +1,7 @@ use oxc_ast::{ AstKind, - ast::{TSSignature, TSType, TSTypeName}, + ast::{TSSignature, TSTupleElement, TSType, TSTypeName}, + match_ts_type, }; use oxc_diagnostics::OxcDiagnostic; use oxc_macros::declare_oxc_lint; @@ -448,8 +449,12 @@ fn references_identifier(type_: &TSType, name: &str) -> bool { || references_identifier(&i.index_type, name) } TSType::TSArrayType(a) => references_identifier(&a.element_type, name), - TSType::TSTupleType(t) => t.element_types.iter().any(|e| { - if let Some(ty) = e.as_ts_type() { references_identifier(ty, name) } else { false } + TSType::TSTupleType(t) => t.element_types.iter().any(|e| match e { + TSTupleElement::TSOptionalType(opt) => { + references_identifier(&opt.type_annotation, name) + } + TSTupleElement::TSRestType(rest) => references_identifier(&rest.type_annotation, name), + match_ts_type!(TSTupleElement) => references_identifier(e.to_ts_type(), name), }), TSType::TSTypeLiteral(lit) => lit.members.iter().any(|m| { if let TSSignature::TSIndexSignature(sig) = m { @@ -461,6 +466,13 @@ fn references_identifier(type_: &TSType, name: &str) -> bool { TSType::TSFunctionType(f) => references_identifier(&f.return_type.type_annotation, name), TSType::TSTypeOperatorType(op) => references_identifier(&op.type_annotation, name), TSType::TSParenthesizedType(p) => references_identifier(&p.type_annotation, name), + TSType::TSNamedTupleMember(m) => match &m.element_type { + TSTupleElement::TSOptionalType(opt) => { + references_identifier(&opt.type_annotation, name) + } + TSTupleElement::TSRestType(rest) => references_identifier(&rest.type_annotation, name), + e @ match_ts_type!(TSTupleElement) => references_identifier(e.to_ts_type(), name), + }, _ => false, } } @@ -878,6 +890,12 @@ fn test() { ", None, ), + ( + "interface Foo { } interface Bar { } type Baz = T; + export type Error = Foo & { [P in Baz]: [P?]; }; + ", + None, + ), ]; let fail = vec![