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

TypeScript types: suggest omitting Float32Array type #464

Open
ddadamhooper opened this issue Feb 28, 2024 · 0 comments
Open

TypeScript types: suggest omitting Float32Array type #464

ddadamhooper opened this issue Feb 28, 2024 · 0 comments

Comments

@ddadamhooper
Copy link
Contributor

ddadamhooper commented Feb 28, 2024

  1. With noUncheckedIndexAccess enabled, TypeScript gives the wrong types when destructuring:
function doSomething([x, y]: ReadonlyVec2) {
    console.log(x + y); // error: typeof x = number | undefined
}
  1. TypeScript doesn't throw errors when it "should":
function doSomething([x, y, z]: ReadonlyVec2) {
                         // ^^ should be type error!
}

Related: #381.

At Datadog, we've built our "solution": we used yarn patch to simply erase Float32Array as a type. TypeScript now treats gl-matrix objects as tuples.

The downside: without accepting Float32Array, it's hard to cast Float32Array to vec2. That's no problem if callers only use vec2.create() and vec2.fromValues(). But it's a problem if callers are allocating a Float32Array themselves and doing vector math on slices of it.

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

1 participant