Skip to content

Unable to destructure TypedArrays #20623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
miklossuveges opened this issue Dec 11, 2017 · 3 comments
Open

Unable to destructure TypedArrays #20623

miklossuveges opened this issue Dec 11, 2017 · 3 comments
Assignees
Labels
Committed The team has roadmapped this issue Suggestion An idea for TypeScript

Comments

@miklossuveges
Copy link

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.

@miklossuveges miklossuveges changed the title Unable to use destructure TypedArrays Unable to destructure TypedArrays Dec 11, 2017
@RyanCavanaugh
Copy link
Member

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

@rbuckton
Copy link
Member

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

@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Jan 10, 2018
@RyanCavanaugh RyanCavanaugh added Committed The team has roadmapped this issue and removed In Discussion Not yet reached consensus labels Jan 30, 2018
@RyanCavanaugh
Copy link
Member

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Committed The team has roadmapped this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants