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 · 2 comments
Open

TypedArray is missing from lib.dom #60861

trusktr opened this issue Dec 27, 2024 · 2 comments
Labels
Duplicate An existing issue was already created

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.

@nmain
Copy link

nmain commented Dec 30, 2024

You're reporting two separate issues here:

However that appears to be untrue in all browsers,

On a side note, I think what MDN means by "directly visible" is just that globalThis.TypedArray does not exist, not that the value is unobservable by any means.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants