Typescript: BindingPattern can't be marked optional using question mark in implementation signature

Created on 16 Apr 2015  ·  2Comments  ·  Source: microsoft/TypeScript

In the section 3.8.2.2:

A parameter can be marked optional by following its name or binding pattern with a question mark (?) or by including an initializer. Initializers (including binding property or element initializers) are permitted only when the parameter list occurs in conjunction with a function body

However, following code:

function d1([a,b,c]?) {}  // Error; binding pattern parameter can't be optional in an implementation parameter
function d1([a,b,c]?);  // Allow

We should update the spec to indicate this difference because by only indicating that "A parameter can be marked optional by following its name or binding pattern with a question mark" is a bit misleading since it is only allow in non-implementation signature

Spec

Most helpful comment

Just realized it is possible to accomplish this! Just use the following:

function d1([a,b,c]=[]) {}

This issue could probably be closed, unless I'm missing something else. (Which I might be 😉 )

All 2 comments

❗️

This would be ridiculously useful! 😃

I have no idea how to submit a PR for this issue, but would be more than willing to put in the work if someone could give a little guidance!

Just realized it is possible to accomplish this! Just use the following:

function d1([a,b,c]=[]) {}

This issue could probably be closed, unless I'm missing something else. (Which I might be 😉 )

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fwanicka picture fwanicka  ·  3Comments

dlaberge picture dlaberge  ·  3Comments

Antony-Jones picture Antony-Jones  ·  3Comments

zhuravlikjb picture zhuravlikjb  ·  3Comments

kyasbal-1994 picture kyasbal-1994  ·  3Comments