Types when destructuring arrays

thr0w picture thr0w · Aug 10, 2015 · Viewed 20.8k times · Source
function f([a,b,c]) {
  // this works but a,b and c are any
}

it's possible write something like that?

function f([a: number,b: number,c: number]) {
  // being a, b and c typed as number 
}

Answer

Ryan Cavanaugh picture Ryan Cavanaugh · Aug 10, 2015

This is the proper syntax for destructuring an array inside an argument list:

function f([a,b,c]: [number, number, number]) {

}