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

ArrayBuffer is returned as ArrayBufferLike which causes issues #9364

Open
CraigglesO opened this issue Mar 11, 2024 · 0 comments
Open

ArrayBuffer is returned as ArrayBufferLike which causes issues #9364

CraigglesO opened this issue Mar 11, 2024 · 0 comments
Labels
bug Something isn't working typescript Something for TypeScript

Comments

@CraigglesO
Copy link

CraigglesO commented Mar 11, 2024

What version of Bun is running?

1.0.29+a146856d1

What platform is your computer?

Darwin 23.1.0 arm64 arm

What steps can reproduce the bug?

Writing browser code, when I create an actual ArrayBuffer, its instead returned as an ArrayBufferLike, which doesn't perfectly align with an ArrayBuffer causes linting errors:

export interface MapID {
  mapID: string
}
export interface WorkerMessageBase extends MapID {
  tileID: bigint
  sourceName: string
}

export interface LineData extends WorkerMessageBase {
  type: 'line'
  vertexBuffer: ArrayBuffer
  lengthSoFarBuffer: ArrayBuffer
  featureGuideBuffer: ArrayBuffer
}

// Upon building the batches, convert to buffers and ship.
    const vertexBuffer = new Float32Array(vertices).buffer
    const lengthSoFarBuffer = new Float32Array(lengthSoFar).buffer
    const featureGuideBuffer = new Float32Array(featureGuide).buffer
    // ship the vector data.
    const data: LineData = {
      mapID,
      type: 'line',
      sourceName,
      tileID,
      vertexBuffer,
      lengthSoFarBuffer,
      featureGuideBuffer
    }
    postMessage(data, [vertexBuffer, featureGuideBuffer])

The linting error for LineData:

Type 'ArrayBufferLike' is not assignable to type 'ArrayBuffer'.
  Property 'resize' is missing in type 'SharedArrayBuffer' but required in type 'ArrayBuffer'.ts(2322)
globals.d.ts(1549, 5): 'resize' is declared here.
worker.spec.ts(416, 3): The expected type comes from property 'vertexBuffer' which is declared here on type 'LineData'
(property) LineData.vertexBuffer: ArrayBuffer

The linting error for postMessage:

No overload matches this call.
  The last overload gave the following error.
    Type 'ArrayBufferLike[]' has no properties in common with type 'WindowPostMessageOptions'.ts(2769)
lib.dom.d.ts(27400, 18): The last overload is declared here.
const vertexBuffer: ArrayBufferLike

Obviously fixable by just saying const vertexBuffer = new Float32Array(vertices).buffer as ArrayBuffer for now, but I figured this should be reported.

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

@CraigglesO CraigglesO added bug Something isn't working typescript Something for TypeScript labels Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working typescript Something for TypeScript
Projects
None yet
Development

No branches or pull requests

1 participant