fix(linter): avoid crash if no members in TSTypeLiteral in typescript/prefer-function-type (#2604)

This commit is contained in:
Wenzhe Wang 2024-03-04 22:57:02 +08:00 committed by GitHub
parent f6709e4737
commit 951297ee59
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -371,8 +371,10 @@ impl Rule for PreferFunctionType {
union_type.types.iter().for_each(|ts_type| { union_type.types.iter().for_each(|ts_type| {
if let TSType::TSTypeLiteral(literal) = ts_type { if let TSType::TSTypeLiteral(literal) = ts_type {
let body = &literal.members; let body = &literal.members;
if body.len() == 1 {
check_member(&body[0], node, ctx); check_member(&body[0], node, ctx);
} }
}
}); });
} }
@ -450,6 +452,7 @@ fn test() {
(): void; (): void;
} }
", ",
"let foo: number | {};",
]; ];
let fail = vec![ let fail = vec![