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,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![