mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 11:54:44 -06:00
fix(37703): forbid required parameter after optional (#38155)
This commit is contained in:
parent
d86bdf4e5c
commit
c219fdae08
@ -37048,10 +37048,9 @@ namespace ts {
|
||||
return grammarErrorOnNode(parameter.name, Diagnostics.A_rest_parameter_cannot_have_an_initializer);
|
||||
}
|
||||
}
|
||||
else if (parameter.questionToken) {
|
||||
else if (isOptionalParameter(parameter)) {
|
||||
seenOptionalParameter = true;
|
||||
|
||||
if (parameter.initializer) {
|
||||
if (parameter.questionToken && parameter.initializer) {
|
||||
return grammarErrorOnNode(parameter.name, Diagnostics.Parameter_cannot_have_question_mark_and_initializer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
tests/cases/conformance/jsdoc/0.js(7,20): error TS1016: A required parameter cannot follow an optional parameter.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsdoc/0.js (1 errors) ====
|
||||
// @ts-check
|
||||
/**
|
||||
* @param {number} a
|
||||
* @param {number} [b]
|
||||
* @param {number} c
|
||||
*/
|
||||
function foo(a, b, c) {}
|
||||
~
|
||||
!!! error TS1016: A required parameter cannot follow an optional parameter.
|
||||
|
||||
18
tests/baselines/reference/checkJsdocOptionalParamOrder.js
Normal file
18
tests/baselines/reference/checkJsdocOptionalParamOrder.js
Normal file
@ -0,0 +1,18 @@
|
||||
//// [0.js]
|
||||
// @ts-check
|
||||
/**
|
||||
* @param {number} a
|
||||
* @param {number} [b]
|
||||
* @param {number} c
|
||||
*/
|
||||
function foo(a, b, c) {}
|
||||
|
||||
|
||||
//// [0.js]
|
||||
// @ts-check
|
||||
/**
|
||||
* @param {number} a
|
||||
* @param {number} [b]
|
||||
* @param {number} c
|
||||
*/
|
||||
function foo(a, b, c) { }
|
||||
@ -0,0 +1,13 @@
|
||||
=== tests/cases/conformance/jsdoc/0.js ===
|
||||
// @ts-check
|
||||
/**
|
||||
* @param {number} a
|
||||
* @param {number} [b]
|
||||
* @param {number} c
|
||||
*/
|
||||
function foo(a, b, c) {}
|
||||
>foo : Symbol(foo, Decl(0.js, 0, 0))
|
||||
>a : Symbol(a, Decl(0.js, 6, 13))
|
||||
>b : Symbol(b, Decl(0.js, 6, 15))
|
||||
>c : Symbol(c, Decl(0.js, 6, 18))
|
||||
|
||||
13
tests/baselines/reference/checkJsdocOptionalParamOrder.types
Normal file
13
tests/baselines/reference/checkJsdocOptionalParamOrder.types
Normal file
@ -0,0 +1,13 @@
|
||||
=== tests/cases/conformance/jsdoc/0.js ===
|
||||
// @ts-check
|
||||
/**
|
||||
* @param {number} a
|
||||
* @param {number} [b]
|
||||
* @param {number} c
|
||||
*/
|
||||
function foo(a, b, c) {}
|
||||
>foo : (a: number, b?: number, c: number) => void
|
||||
>a : number
|
||||
>b : number
|
||||
>c : number
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
tests/cases/conformance/jsdoc/a.js(5,18): error TS1016: A required parameter cannot follow an optional parameter.
|
||||
|
||||
|
||||
==== tests/cases/conformance/jsdoc/a.js (1 errors) ====
|
||||
/**
|
||||
* @param {string=} `args`
|
||||
* @param `bwarg` {?number?}
|
||||
*/
|
||||
function f(args, bwarg) {
|
||||
~~~~~
|
||||
!!! error TS1016: A required parameter cannot follow an optional parameter.
|
||||
}
|
||||
|
||||
==== tests/cases/conformance/jsdoc/ts.ts (0 errors) ====
|
||||
/**
|
||||
* @param `arg` - this is fine
|
||||
*/
|
||||
function g(arg: string) {
|
||||
}
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
// @allowJS: true
|
||||
// @suppressOutputPathCheck: true
|
||||
|
||||
// @filename: 0.js
|
||||
// @ts-check
|
||||
/**
|
||||
* @param {number} a
|
||||
* @param {number} [b]
|
||||
* @param {number} c
|
||||
*/
|
||||
function foo(a, b, c) {}
|
||||
Loading…
x
Reference in New Issue
Block a user