destructuring assignment typescript error

I have a function getMoveLocation that return array [col, row]. Then I want to use it like this
const [lastCol, lastRow] = getMoveLocation(lastSquares, squares)
const [lastCol, lastRow] = getMoveLocation(lastSquares, squares)
But typescript yells at me
Type 'number[] | undefined' must have a '[Symbol.iterator]()' method that returns an iterator.
Type 'number[] | undefined' must have a '[Symbol.iterator]()' method that returns an iterator.
Anyone maybe know solution?
2 Replies
whatplan
whatplan2y ago
returning as const may help? Worth a shot
Tom
Tom2y ago
^ cast the return type to [number , number] as const but also you cant destructure if the function can return undefined
Want results from more Discord servers?
Add your server