Types when destructuring arrays Ask Question

Types when destructuring arrays Ask Question
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 
}

ベストアンサー1

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

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

}

おすすめ記事