From 365bb7db8f00532588088f01976dc5531228eaf9 Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Thu, 26 Mar 2026 17:06:08 +0000 Subject: [PATCH] fix(linter): skip typed nested literals in explicit-module-boundary-types (#20776) fixes #20434 --- .../explicit_module_boundary_types.rs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/oxc_linter/src/rules/typescript/explicit_module_boundary_types.rs b/crates/oxc_linter/src/rules/typescript/explicit_module_boundary_types.rs index e37635b718ea5..b0eb9a079222e 100644 --- a/crates/oxc_linter/src/rules/typescript/explicit_module_boundary_types.rs +++ b/crates/oxc_linter/src/rules/typescript/explicit_module_boundary_types.rs @@ -706,21 +706,21 @@ impl<'a> Visit<'a> for ExplicitTypesChecker<'a, '_> { } fn visit_ts_as_expression(&mut self, it: &TSAsExpression<'a>) { - if is_wrapped_function_expression(&it.expression) { + if is_skippable_typed_expression(&it.expression) { return; } walk::walk_ts_as_expression(self, it); } fn visit_ts_satisfies_expression(&mut self, it: &TSSatisfiesExpression<'a>) { - if is_wrapped_function_expression(&it.expression) { + if is_skippable_typed_expression(&it.expression) { return; } walk::walk_ts_satisfies_expression(self, it); } fn visit_ts_type_assertion(&mut self, it: &TSTypeAssertion<'a>) { - if is_wrapped_function_expression(&it.expression) { + if is_skippable_typed_expression(&it.expression) { return; } walk::walk_ts_type_assertion(self, it); @@ -736,10 +736,13 @@ fn get_typed_inner_expression<'a, 'e>(expr: &'e Expression<'a>) -> &'e Expressio } } -fn is_wrapped_function_expression(expr: &Expression<'_>) -> bool { +fn is_skippable_typed_expression(expr: &Expression<'_>) -> bool { matches!( get_typed_inner_expression(expr), - Expression::ArrowFunctionExpression(_) | Expression::FunctionExpression(_) + Expression::ArrowFunctionExpression(_) + | Expression::FunctionExpression(_) + | Expression::ObjectExpression(_) + | Expression::ArrayExpression(_) ) } @@ -1610,6 +1613,13 @@ mod test { ", None, ), + ( + " + interface T { f: () => number; } + export const NESTED_OBJ = { t: { f: () => 42, } satisfies T, }; + ", + None, + ), ]; let fail = vec![