- With
noUncheckedIndexAccess enabled, TypeScript gives the wrong types when destructuring:
function doSomething([x, y]: ReadonlyVec2) {
console.log(x + y); // error: typeof x = number | undefined
}
- 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.
noUncheckedIndexAccessenabled, TypeScript gives the wrong types when destructuring:Related: #381.
At Datadog, we've built our "solution": we used
yarn patchto simply eraseFloat32Arrayas a type. TypeScript now treats gl-matrix objects as tuples.The downside: without accepting
Float32Array, it's hard to castFloat32Arraytovec2. That's no problem if callers only usevec2.create()andvec2.fromValues(). But it's a problem if callers are allocating a Float32Array themselves and doing vector math on slices of it.