-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this
Milestone
Description
lib Update Request
Configuration Check
My compilation target is ES2021 and my lib is ["DOM", "DOM.Iterable", "ES2021"]. TypeScript version is 4.9.5.
Missing / Incorrect Definition
The DataView constructor parameter type is incorrectly broad by accepting ArrayBufferLike because TypedArray's such as Uint8Array match the ArrayBufferLike type but are not valid parameters. I think the DataView constructor parameter should only accept ArrayBuffer | SharedArrayBuffer.
Sample Code
The following produces no error in TypeScript but does produce an error in Node 16, Chrome 109, and FireFox 111b1:
new DataView(new Uint8Array(32));The runtime error is:
Uncaught TypeError: First argument to DataView constructor must be an ArrayBuffer
at new DataView (<anonymous>)
The correct code that does run is:
new DataView(new Uint8Array(32).buffer)Documentation Link
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView/DataView
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/buffer
- https://tc39.es/ecma262/multipage/structured-data.html#sec-dataview-constructor (specifically a
TypeErroris to be thrown if this is a detached buffer, i.e. without array buffer data)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this