fix(49869): throw an error on optional binding pattern parameter in JavaScript (#50094)

This commit is contained in:
Oleksandr T
2022-07-29 16:05:34 -07:00
committed by GitHub
parent 88a1e3a1dd
commit ae7d2325e9
5 changed files with 58 additions and 1 deletions
+1 -1
View File
@@ -35230,7 +35230,7 @@ namespace ts {
error(node.name, Diagnostics.constructor_cannot_be_used_as_a_parameter_property_name);
}
}
if (node.questionToken && isBindingPattern(node.name) && (func as FunctionLikeDeclaration).body) {
if ((node.questionToken || isJSDocOptionalParameter(node)) && isBindingPattern(node.name) && (func as FunctionLikeDeclaration).body) {
error(node, Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature);
}
if (node.name && isIdentifier(node.name) && (node.name.escapedText === "this" || node.name.escapedText === "new")) {
@@ -0,0 +1,16 @@
/a.js(9,12): error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
==== /a.js (1 errors) ====
/**
* @typedef Foo
* @property {string} a
*/
/**
* @param {Foo} [options]
*/
function f({ a = "a" }) {}
~~~~~~~~~~~
!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature.
@@ -0,0 +1,13 @@
=== /a.js ===
/**
* @typedef Foo
* @property {string} a
*/
/**
* @param {Foo} [options]
*/
function f({ a = "a" }) {}
>f : Symbol(f, Decl(a.js, 0, 0))
>a : Symbol(a, Decl(a.js, 8, 12))
@@ -0,0 +1,14 @@
=== /a.js ===
/**
* @typedef Foo
* @property {string} a
*/
/**
* @param {Foo} [options]
*/
function f({ a = "a" }) {}
>f : ({ a }?: Foo) => void
>a : string
>"a" : "a"
@@ -0,0 +1,14 @@
// @checkJs: true
// @allowJs: true
// @noEmit: true
// @filename: /a.js
/**
* @typedef Foo
* @property {string} a
*/
/**
* @param {Foo} [options]
*/
function f({ a = "a" }) {}