Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JS Closure Compiler, @param syntax for array destructuring?

I'm unable to find the correct syntax for @param annotations for array destructuring. E.g.:

let destructArray = ([one, two]) => one + two;

I tried imitating the object destructuring syntax:

// object destructuring works
/** @param {{one: number, two: number}} o */
let destructObject = ({one, two}) => one + two;

// array destructuring does not works
/** @param {[one: number, two: number]} a */
let destructArray = ([one, two]) => one + two;

But that's not valid syntax. I've also tried /** @param {Array<number>} a */, but then it expects a single parameter named a, not one and two.

Does anyone know the correct syntax to use for array destructuring?

like image 770
junvar Avatar asked Sep 03 '25 10:09

junvar


1 Answers

Closure Compiler does not currently support different types at different array indexes. So in this case, all you do is:

/** @type {function(!Array<number>):number} */
let destructArray = ([one, two]) => one + two;
like image 57
Chad Killingsworth Avatar answered Sep 05 '25 01:09

Chad Killingsworth