# Looking for ideas: named argument with destructuring

**URL:** <https://es.discourse.group/t/looking-for-ideas-named-argument-with-destructuring/1590>\
**Category:** 💡 Ideas\
**Created:** [January 14, 2023, 8:28pm UTC](https://es.discourse.group/t/looking-for-ideas-named-argument-with-destructuring/1590 "2023-01-14T20:28:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![conartist6](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/conartist6/32/515_2.png) [@conartist6](https://es.discourse.group/u/conartist6)\
**Post date:** [January 14, 2023, 8:28pm UTC](https://es.discourse.group/t/looking-for-ideas-named-argument-with-destructuring/1590/1 "2023-01-14T20:28:14Z")

</div>

Sometimes I want to have a named argument but also destructure from it in a single definition. It happens most often when I'm using the keyword-args style of coding that has become relatively common. I'll end up writing something like this:

```javascript
let setWithKeywordArgs = (
  id = 0,
  props = {},
) => {
  const {
    disable = false,
    name = 'Submit',
  } = props;
  // ...
}

```

The problem I have with this is that JS nearly invented an awesome self-documenting capability where a function's arguments read without its body form a declarative description of what the function considers its arguments.

Imagine I were able to write somethingthat read more like this instead:

```javascript
let setWithKeywordArgs = (
  id = 0,
  props {
    disable = false,
    name = 'Submit',
  } = {},
) => {
  return new Boolean;
}

```

Now it would be the world's easiest project to strip this down to the self-documenting keyword-args-supporting signature:

```javascript
setWithKeywordArgs = (
  id = 0,
  props {
    disable = false,
    name = 'Submit',
  } = {},
) => Boolean

```

Of course it is already possible to do this by omitting the name of the keyword-args-like argument, but this is not without significant drawbacks. The parameter name is really gone, and will be unavailable for code intelligence or to assist in the creation of documentation. Furthermore the implementation of the method will be unable to forward its complete keyword arguments to another function.

Does anyone have any thoughts on why this hasn't happened already?  
What syntaxes are theoretically plausible?

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [January 14, 2023, 8:36pm UTC](https://es.discourse.group/t/looking-for-ideas-named-argument-with-destructuring/1590/2 "2023-01-14T20:36:24Z")

</div>

With [GitHub - zkat/proposal-as-patterns: `as` destructuring patterns](https://github.com/zkat/proposal-as-patterns) this would be:

```javascript
const setWithKeywordArgs = (
 {
    disable = false,
    name = 'Submit',
 } as props = {}
) => { ... }

```

Or if the new syntax in [pattern-matching](https://github.com/tc39/proposal-pattern-matching) was extending to work in existing binding places:

```javascript
const setWithKeywordArgs = (
 props and {
    disable = false,
    name = 'Submit',
 } = {}
) => { ... }

```

---

<div class="post-metadata">

**Author:** ![conartist6](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/conartist6/32/515_2.png) [@conartist6](https://es.discourse.group/u/conartist6)\
**Post date:** [January 15, 2023, 1:25am UTC](https://es.discourse.group/t/looking-for-ideas-named-argument-with-destructuring/1590/3 "2023-01-15T01:25:52Z")

</div>

I don't like the `as` syntax as much because it feels like to match its meaning in import it should be reversed: `actual as { destructured }`, and I also think it's important to keep the name of the argument first for the purposes of rapid visual scannning.

It does actually work not to put any keyword there doesn't it? Destructuring braces like `[` and `{` aren't syntactically valid after an argument name anyway.
