Closed as not planned
Description
⚙ Compilation target
n/a
⚙ Library
lib.dom.d.ts
Missing / Incorrect Definition
TypedArray
is missing from typed array classes.
Sample Code
In all browsers, this works:
console.log(Float64Array.__proto__) // Logs the "TypedArray" constructor.
Currently that code gives the type error
Property '__proto__' does not exist on type 'Float64ArrayConstructor'. ts(2339)
Documentation Link
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
The MDN doc mentions:
There is no global property named TypedArray, nor is there a directly visible TypedArray constructor
However that appears to be untrue in all browsers, TypedArray
is visible on the prototype of any typed array constructor.
It would be nice if lib.dom was able to represent this class somehow, such that it would be possible to do the following to make it easy to reference the base class:
const TypedArray = Float32Array.__proto__
console.log(new Float64Array() instanceof TypedArray) // logs "true" in all browsers
console.log(new Int8Array() instanceof TypedArray) // logs "true" in all browsers
console.log(new Int16Array() instanceof TypedArray) // logs "true" in all browsers
console.log(new Int32Array() instanceof TypedArray) // logs "true" in all browsers
console.log(new Uint8Array() instanceof TypedArray) // logs "true" in all browsers
console.log(new BigInt64Array() instanceof TypedArray) // logs "true" in all browsers
This would also simplify certain functions, for example:
function doSomethingWithTypedArray(array: TypedArray) {
// ...Does something with any sort of typed array...
}