Blake H
Blake H

Reputation: 451

Ignore multiple results of a destructuring in typescript

I'm using typescript destructuring as follows:

const props = new Map<User, [Name, Age, Location, Gender]>();
props.set(bill, [n, a, l, g]);

// ...

// Want to access location and gender of bill.
const [n, a, l, g] = props.get(bill);
console.log(l + g);

But this violates the noUnusedLocals compiler option, so what I really want is:

const [_, _, l, g] = props.get(bill);

but this violates a redeclaration of a block-scope variable (two variables named _).

What's the best way to deal with this? Perhaps destructuring is just the wrong choice here.

Upvotes: 6

Views: 1901

Answers (1)

toskv
toskv

Reputation: 31600

According to the ES6 documentation you can do it this way:

const [, , l, g] = props.get(bill);

You can find a minimal working example here.

Upvotes: 8

Related Questions