Looking for ideas: named argument with destructuring

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:

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:

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:

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?

With GitHub - zkat/proposal-as-patterns: `as` destructuring patterns this would be:

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

Or if the new syntax in pattern-matching was extending to work in existing binding places:

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

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.