0

So I am using typescript and node, currently have it able to compile down to js. As I learn more about strictly typing js, I am curious as how the proper way to type declarations that are destructured. I cannot seem to find a proper link or know exactly where to look. I have read quite a few github issues and conversations on ways they were thinking to type destructured arrays and objects. None have been really "liked" by the typescript compiler.

So for example : If I have an object

const arr= [ [1,2,3,4,5] ]

In my implementation I am actually iterating over the id array and using the id at that index so ideally each iteration I am pulling an id like so

const [ id ] = arr[0]

Since id will always be a number, would I do

const [ id: number ] = arr[0] //or
const [ id ] : number = arr[0] // or neither?
jfriend00
  • 683,504
  • 96
  • 985
  • 979
cheussy
  • 361
  • 2
  • 11

0 Answers0