Skip to content

Commit 746b318

Browse files
camc314Boshen
authored andcommitted
fix(linter): false positive in typescript/explicit-function-return-type with satisfies (#10668)
when working on #10667, i noticed these tests were missing from our suite. this PR ports over the tests and fixes them typescript/eslint PR typescript-eslint/typescript-eslint#10315
1 parent cce1043 commit 746b318

File tree

1 file changed

+62
-4
lines changed

1 file changed

+62
-4
lines changed

crates/oxc_linter/src/rules/typescript/explicit_function_return_type.rs

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,14 @@ impl ExplicitFunctionReturnType {
420420
let AstKind::ArrowFunctionExpression(func) = node.kind() else { return false };
421421
let Some(expr) = func.get_expression() else { return false };
422422

423+
let mut expr = expr;
424+
loop {
425+
expr = match expr {
426+
Expression::TSSatisfiesExpression(e) => &e.expression,
427+
_ => break,
428+
};
429+
}
430+
423431
match expr {
424432
Expression::TSAsExpression(ts_expr) => {
425433
let TSType::TSTypeReference(ts_type) = &ts_expr.type_annotation else {
@@ -606,7 +614,10 @@ fn is_typed_jsx(node: &AstNode) -> bool {
606614
}
607615

608616
fn is_function(expr: &Expression) -> bool {
609-
matches!(expr, Expression::ArrowFunctionExpression(_) | Expression::FunctionExpression(_))
617+
matches!(
618+
expr.get_inner_expression(),
619+
Expression::ArrowFunctionExpression(_) | Expression::FunctionExpression(_)
620+
)
610621
}
611622

612623
fn ancestor_has_return_type<'a>(node: &AstNode<'a>, ctx: &LintContext<'a>) -> bool {
@@ -1145,9 +1156,56 @@ fn test() {
11451156
),
11461157
(
11471158
"
1148-
new Promise(resolve => {});
1149-
new Foo(1, () => {});
1150-
",
1159+
interface R {
1160+
type: string;
1161+
value: number;
1162+
}
1163+
1164+
const func = (value: number) => ({ type: 'X', value }) as const satisfies R;
1165+
",
1166+
Some(
1167+
serde_json::json!([ { "allowDirectConstAssertionInArrowFunctions": true, }, ]),
1168+
),
1169+
None,
1170+
None,
1171+
),
1172+
(
1173+
"
1174+
interface R {
1175+
type: string;
1176+
value: number;
1177+
}
1178+
1179+
const func = (value: number) =>
1180+
({ type: 'X', value }) as const satisfies R satisfies R;
1181+
",
1182+
Some(
1183+
serde_json::json!([ { "allowDirectConstAssertionInArrowFunctions": true, }, ]),
1184+
),
1185+
None,
1186+
None,
1187+
),
1188+
(
1189+
"
1190+
interface R {
1191+
type: string;
1192+
value: number;
1193+
}
1194+
1195+
const func = (value: number) =>
1196+
({ type: 'X', value }) as const satisfies R satisfies R satisfies R;
1197+
",
1198+
Some(
1199+
serde_json::json!([ { "allowDirectConstAssertionInArrowFunctions": true, }, ]),
1200+
),
1201+
None,
1202+
None,
1203+
),
1204+
(
1205+
"
1206+
new Promise(resolve => {});
1207+
new Foo(1, () => {});
1208+
",
11511209
Some(serde_json::json!([ { "allowTypedFunctionExpressions": true, }, ])),
11521210
None,
11531211
None,

0 commit comments

Comments
 (0)