You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Update TypedArray constructors to disallow invalid (typedArray, byteOffset, byteLength) #44191
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
constbuf=newArrayBuffer(1024);constuint8=newUint8Array(buf,16,128)// No TS error, even though the `16` and `32` are completely ignoredconstsubUint8=newUint8Array(uint8,16,32)subUint8.byteLength// Oops, this is 128, not 32.
newUint8Array();// new in ES2017newUint8Array(length);newUint8Array(typedArray);newUint8Array(object);newUint8Array(buffer);newUint8Array(buffer,byteOffset);newUint8Array(buffer,byteOffset,length);
The constructor call from the report is now rejected. TypeScript 6.0.3 and current native TypeScript 7.1.0-dev.20260906.1 report TS2769 because the overload with byteOffset and length requires an ArrayBuffer or ArrayBufferLike as its first argument; another typed array does not match that overload.
TypeScript 4.3.2 accepted the call, so its offset and length arguments could be ignored at runtime.
Activity
RyanCavanaugh commentedon Sep 7, 2026
The constructor call from the report is now rejected. TypeScript 6.0.3 and current native TypeScript 7.1.0-dev.20260906.1 report TS2769 because the overload with
byteOffsetandlengthrequires anArrayBufferorArrayBufferLikeas its first argument; another typed array does not match that overload.TypeScript 4.3.2 accepted the call, so its offset and length arguments could be ignored at runtime.