iTwin / itwinjs-core

Monorepo for iTwin.js Library
https://www.itwinjs.org
MIT License
620 stars 210 forks source link

`registerWorker` typing does not allow async function returning a transferable struct #7248

Closed mdastous-bentley closed 1 month ago

mdastous-bentley commented 1 month ago

Trying to call registerWorker on a WorkerImplementation that contain an async function returning a transferrable (i.e. {result, transfer}), will give this typing error:

Type '() => Promise<{ result: number; transfer: never[]; }>' is not assignable to type '() => WorkerReturnType<() => Promise<number>>'.
  Type 'Promise<{ result: number; transfer: never[]; }>' is not assignable to type 'WorkerReturnType<() => Promise<number>>'.
    Type 'Promise<{ result: number; transfer: never[]; }>' is not assignable to type 'Promise<number>'.
      Type '{ result: number; transfer: never[]; }' is not assignable to type 'number'.

To Reproduce This PR can be used to reproduce the error with the actual tests.

Expected behavior No typing error.