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

TypedArray is missing from lib.dom #60861

Open
trusktr opened this issue Dec 27, 2024 · 1 comment
Open

TypedArray is missing from lib.dom #60861

trusktr opened this issue Dec 27, 2024 · 1 comment

Comments

@trusktr
Copy link
Contributor

trusktr commented Dec 27, 2024

⚙ 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...
}
@MartinJohns
Copy link
Contributor

Duplicate of #15402.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants