Search code examples
arraystypescriptparametersdestructuring

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 am I able to do something like this?

// doesn't work
function ([boolValue: boolean, stringValue: string]) {
   // make use of boolValue and stringValue
}

Solution

  • Ok I figured it out, might as well post as an answer. This works:

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