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