Unpack array argument directly to parameters?

I know I can do this:

function (value: [boolean, string]) {
   const [boolValue, stringValue] = value;

   // make use of boolValue and stringValue
}

But can I do something like this?

// doesn't work
function ([boolValue: boolean, stringValue: string]) {
   // make use of boolValue and stringValue
}
+4
source share
1 answer

Well, I figured this out, could also post an answer. It works:

function ([boolValue, stringValue]: [boolean, string]) {
   // make use of boolValue and stringValue
}
+5
source

Source: https://habr.com/ru/post/1657658/


All Articles