diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 7a67c9bc30..f198e333b1 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -51,6 +51,8 @@ Semantic Versioning. [E0034][] ("redeclaration of variable"). * A namespace with the same name as an interface or type alias no longer falsely reports [E0034][] ("redeclaration of variable"). + * `(a?, ...b) => ReturnType` in a TypeScript type no longer falsely reports + [E0379][] ("optional parameter cannot be followed by a required parameter"). * Nested `module` declarations no longer falsely report [E0361][]. E0361's message has been changed: * Before: "module with string name is only allowed at the top level" diff --git a/src/quick-lint-js/fe/parse-statement.cpp b/src/quick-lint-js/fe/parse-statement.cpp index 1051a7dc25..ed69e3267c 100644 --- a/src/quick-lint-js/fe/parse-statement.cpp +++ b/src/quick-lint-js/fe/parse-statement.cpp @@ -2494,7 +2494,8 @@ void Parser::parse_and_visit_function_parameters( parameter->child_0()->kind() == Expression_Kind::Optional)) { previous_optional_span = parameter->span(); } else { - if (previous_optional_span.has_value()) { + if (previous_optional_span.has_value() && + parameter->kind() != Expression_Kind::Spread) { this->diag_reporter_->report( Diag_Optional_Parameter_Cannot_Be_Followed_By_Required_Parameter{ .optional_parameter = *previous_optional_span, diff --git a/test/test-parse-typescript-function.cpp b/test/test-parse-typescript-function.cpp index d1375a9c31..62eabd162d 100644 --- a/test/test-parse-typescript-function.cpp +++ b/test/test-parse-typescript-function.cpp @@ -757,6 +757,12 @@ TEST_F(Test_Parse_TypeScript_Function, optional_parameter_in_function_type) { } } +TEST_F(Test_Parse_TypeScript_Function, + optional_parameter_followed_by_rest_parameter_is_allowed) { + test_parse_and_visit_typescript_type_expression( + u8"(param1?, ...rest) => ReturnType"_sv, no_diags, typescript_options); +} + TEST_F(Test_Parse_TypeScript_Function, optional_parameter_followed_by_required) { test_parse_and_visit_typescript_type_expression(