Skip to content

TypeScript types: suggest omitting Float32Array type #464

@ddadamhooper

Description

@ddadamhooper
  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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions