destruct*
wild*
I would like TypeScript to port the wildcard destructuring feature from Haskell.
The examples below throw errors due to redefining _ in the existing implementation. Currently, we have to define named placeholders which draw unnecessary attention to themselves and require an exception in the linter implementations for no-unused-vars. The Haskell approach is much cleaner.
const [_, valICareAbout, _] = someFunc();const eventHandler = (_, _, value) => doSomethingWithValue(value);My suggestion meets these guidelines:
This should be taken up with es-discuss / TC39. We didn't create destructuring syntax
Are you saying that this feature does not "agree with the rest of TypeScript's Design Goals"? I assumed this would be fine for TypeScript, as const [_, valICareAbout, _] = someFunc(); TS would just compile down to const [a, valICareAbout, b] = someFunc(); ES.
We're trying to scope TypeScript's additions to those necessary to add static typing to JavaScript. This isn't one of those things, it'd just be new sugar for existing behavior that the TC39 committee created. If TC39 wanted to have duplicated destructuring identifiers cancel each other out, or have _ just evaporate, they could have written it that way, but they didn't, and they're in charge of the behavior of the language.
Doesn't JS/TS already support omitting a variable when you destructure? Like
const [ , valICareAbout, ] = someFunc();
You're too practical @jcalz β₯
Most helpful comment
Doesn't JS/TS already support omitting a variable when you destructure? Like