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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With