Skip to content
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

Update TypedArray constructors to disallow invalid (typedArray, byteOffset, byteLength) #44191

Open
tjjfvi opened this issue May 20, 2021 · 0 comments · May be fixed by #50450
Open

Update TypedArray constructors to disallow invalid (typedArray, byteOffset, byteLength) #44191

tjjfvi opened this issue May 20, 2021 · 0 comments · May be fixed by #50450
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fix Available A PR has been opened for this issue Help Wanted You can do this
Milestone

Comments

@tjjfvi
Copy link
Contributor

tjjfvi commented May 20, 2021

lib Update Request

Configuration Check

My compilation target is ES2020 and my lib is the default.

Missing / Incorrect Definition

TypedArray constructors allows passing (TypedArray, byteOffset, byteLength), when only byteOffset and byteLength are only used when passing in an ArrayBuffer

Sample Code

const buf = new ArrayBuffer(1024);
const uint8 = new Uint8Array(buf, 16, 128)
// No TS error, even though the `16` and `32` are completely ignored
const subUint8 = new Uint8Array(uint8, 16, 32)
subUint8.byteLength // Oops, this is 128, not 32.

Documentation Link

MDN on Uint8Array constructor

new Uint8Array(); // new in ES2017
new Uint8Array(length);
new Uint8Array(typedArray);
new Uint8Array(object);

new Uint8Array(buffer);
new Uint8Array(buffer, byteOffset);
new Uint8Array(buffer, byteOffset, length);
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this labels May 20, 2021
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone May 20, 2021
@graphemecluster graphemecluster linked a pull request Nov 9, 2022 that will close this issue
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fix Available A PR has been opened for this issue Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants