Typescript: Unable to destructure TypedArrays

Created on 11 Dec 2017  ·  3Comments  ·  Source: microsoft/TypeScript

TypeScript Version: 2.6.2

Code

const [ foo, bar ] = new Float64Array([42, -42])

Expected behavior:
foo and bar are destructured correctly
All JS engine with support for TypedArrays and destructuring handles this code without any problem

Actual behavior:
Error:error TS2461: Type 'Float64Array' is not an array type.

Committed Suggestion

Most helpful comment

Array.prototype.slice.call works on typed arrays, so we could change the helper.

All 3 comments

We could support this for non-rest destructuring; but the current ... emit uses slice which is not present on TypedArrays. @rbuckton thoughts?

Array.prototype.slice.call works on typed arrays, so we could change the helper.

@rbuckton I was wrong; slice is present on the typed arrays. Does anything stop us from just removing the type error and running with the current emit?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

siddjain picture siddjain  ·  3Comments

uber5001 picture uber5001  ·  3Comments

fwanicka picture fwanicka  ·  3Comments

dlaberge picture dlaberge  ·  3Comments

manekinekko picture manekinekko  ·  3Comments