mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
fix(49869): throw an error on optional binding pattern parameter in JavaScript (#50094)
This commit is contained in:
@@ -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" }) {}
|
||||
Reference in New Issue
Block a user