From 951297ee5900bd437ce410d885a3d2b7e13cd79b Mon Sep 17 00:00:00 2001 From: Wenzhe Wang Date: Mon, 4 Mar 2024 22:57:02 +0800 Subject: [PATCH] fix(linter): avoid crash if no members in TSTypeLiteral in typescript/prefer-function-type (#2604) --- .../oxc_linter/src/rules/typescript/prefer_function_type.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/oxc_linter/src/rules/typescript/prefer_function_type.rs b/crates/oxc_linter/src/rules/typescript/prefer_function_type.rs index 2138983f6..6a8bd3cc3 100644 --- a/crates/oxc_linter/src/rules/typescript/prefer_function_type.rs +++ b/crates/oxc_linter/src/rules/typescript/prefer_function_type.rs @@ -371,7 +371,9 @@ impl Rule for PreferFunctionType { union_type.types.iter().for_each(|ts_type| { if let TSType::TSTypeLiteral(literal) = ts_type { let body = &literal.members; - check_member(&body[0], node, ctx); + if body.len() == 1 { + check_member(&body[0], node, ctx); + } } }); } @@ -450,6 +452,7 @@ fn test() { (): void; } ", + "let foo: number | {};", ]; let fail = vec![