Skip to content

Error Generating type definitions - for ESNext / ES2024 . SharedArrayBuffer vs ArrayBuffer incompatibility - uniffi-bindgen-react-native: 0.28.3-2 #225

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

Open
akkumar opened this issue Mar 1, 2025 · 7 comments

Comments

@akkumar
Copy link

akkumar commented Mar 1, 2025

Environment

$ node --version
v22.14.0

 "typescript": "^5.7.2"

Package.json :

  "dependencies": {
    "uniffi-bindgen-react-native": "^0.28.3-2"
  }

Issue

There is an error when generating typescript definitions when using this bindgen

Specifically this error appears for ESNext ( or - rather implied to be ES2024 as of reporting this issue ).

yarn prepare fails at the step - Generating type definitions with tsc .

$ yarn prepare
..
..
..



ℹ Building target codegen
ℹ Building target commonjs
ℹ Cleaning up previous build at lib/commonjs
ℹ Building target module
ℹ Cleaning up previous build at lib/module
ℹ Building target typescript
ℹ Cleaning up previous build at lib/typescript
ℹ Cleaning up previous iOS codegen native code at ios/generated
ℹ Cleaning up previous Android codegen native code at android/generated
ℹ Compiling 4 files in src with babel
ℹ Compiling 4 files in src with babel
ℹ Generating type definitions with tsc
node_modules/uniffi-bindgen-react-native/typescript/src/ffi-converters.ts:339:9 - error TS2322: Type 'ArrayBufferLike' is not assignable to type 'ArrayBuffer'.
  Type 'SharedArrayBuffer' is missing the following properties from type 'ArrayBuffer': resizable, resize, detached, transfer, transferToFixedLength

339         return ab;
            ~~~~~~

node_modules/uniffi-bindgen-react-native/typescript/src/ffi-converters.ts:342:7 - error TS2322: Type 'ArrayBuffer | SharedArrayBuffer' is not assignable to type 'ArrayBuffer'.
  Type 'SharedArrayBuffer' is missing the following properties from type 'ArrayBuffer': resizable, resize, detached, transfer, transferToFixedLength

342       return ab.slice(start, end);
          ~~~~~~

node_modules/uniffi-bindgen-react-native/typescript/src/ffi-converters.ts:350:7 - error TS2322: Type 'ArrayBufferLike' is not assignable to type 'ArrayBuffer'.
  Type 'SharedArrayBuffer' is missing the following properties from type 'ArrayBuffer': resizable, resize, detached, transfer, transferToFixedLength

350       return from.readArrayBuffer(length);
          ~~~~~~

node_modules/uniffi-bindgen-react-native/typescript/src/ffi-types.ts:35:27 - error TS2345: Argument of type 'ArrayBufferLike' is not assignable to parameter of type 'ArrayBuffer'.
  Type 'SharedArrayBuffer' is missing the following properties from type 'ArrayBuffer': resizable, resize, detached, transfer, transferToFixedLength

35     return new RustBuffer(buf.buffer);
                             ~~~~~~~~~~


Found 4 errors in 2 files.

Errors  Files
     3  node_modules/uniffi-bindgen-react-native/typescript/src/ffi-converters.ts:339
     1  node_modules/uniffi-bindgen-react-native/typescript/src/ffi-types.ts:35
✖ Failed to build definition files.
@akkumar akkumar changed the title Typescript issue: when target is ESNext ( specifically applies to ES2024 ) - SharedArrayBuffer vs ArrayBuffer Generating type definitions fails to ESNext - ES2024 - SharedArrayBuffer vs ArrayBuffer incompatibility Mar 1, 2025
@akkumar akkumar changed the title Generating type definitions fails to ESNext - ES2024 - SharedArrayBuffer vs ArrayBuffer incompatibility Generating type definitions fails for ESNext / ES2024 . SharedArrayBuffer vs ArrayBuffer incompatibility Mar 1, 2025
@akkumar
Copy link
Author

akkumar commented Mar 1, 2025

As a temporary fix - changing the target and lib ( and module ) in tsconfig.json explicitly to ES2022 instead of ESNext gets us past the issue.

{
"compilerOptions": {
    "target": "ES2022",
    "lib": ["ES2022"],
    "module": "ES2022",
    ...

}
}

@akkumar akkumar changed the title Generating type definitions fails for ESNext / ES2024 . SharedArrayBuffer vs ArrayBuffer incompatibility Error Generating type definitions - for ESNext / ES2024 . SharedArrayBuffer vs ArrayBuffer incompatibility Mar 1, 2025
@akkumar
Copy link
Author

akkumar commented Mar 1, 2025

Possible Debugging

Some starting pointers to the debugging of the underlying issue:

As per this link - https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-7.html#support-for---target-es2024-and---lib-es2024 ( "Support for --target es2024 and --lib es2024" )

"Note that as part of the changes to SharedArrayBuffer and ArrayBuffer, the two now diverge a bit. To bridge the gap and preserve the underlying buffer type, all TypedArrays (like Uint8Array and others) .... "

I am not sure of the changes but I believe that could be a starting point to investigate the differences between ES2024 and ES2022 and why this bindgen fails for ES2024.

@akkumar akkumar changed the title Error Generating type definitions - for ESNext / ES2024 . SharedArrayBuffer vs ArrayBuffer incompatibility Error Generating type definitions - for ESNext / ES2024 . SharedArrayBuffer vs ArrayBuffer incompatibility - uniffi-bindgen-react-native: "^0.28.3-2" Mar 2, 2025
@akkumar akkumar changed the title Error Generating type definitions - for ESNext / ES2024 . SharedArrayBuffer vs ArrayBuffer incompatibility - uniffi-bindgen-react-native: "^0.28.3-2" Error Generating type definitions - for ESNext / ES2024 . SharedArrayBuffer vs ArrayBuffer incompatibility - uniffi-bindgen-react-native: 0.28.3-2 Mar 2, 2025
@Johennes
Copy link
Collaborator

Johennes commented Mar 3, 2025

I'm not sure if it's related but we discussed some issues around updating to TS 5.7.2 in #168. TS doesn't seem to use semantic versioning and ^ allows updates up to the next major version. Could you maybe check if you see the same issues when pinning TS to 5.7.2?

@akkumar
Copy link
Author

akkumar commented Mar 6, 2025

As described earlier , the error is specific to two things

  1. Ts pinned to 5.7.2 and
  2. module / lib / target - set to ESNext / ES2024

Both the conditions apply for the error to appear.

@Johennes
Copy link
Collaborator

Johennes commented Mar 7, 2025

I'm sorry, I may be misunderstanding but you said ^5.7.2 which allows anything up to but not including 6.0.0. I just wanted to double check what your resolved TS version is.

@hazelmeow
Copy link

I'm hitting this as well with Typescript 5.7.3. My workaround was changing some instances of ArrayBuffer to ArrayBufferLike in ffi-types.ts and ffi-converters.ts, but I'm not sure if they were correct changes. Specifying UniffiByteArray = Uint8Array<ArrayBuffer> (instead of it defaulting to Uint8Array<ArrayBufferLike>) might also lead to a solution?

@akkumar
Copy link
Author

akkumar commented Mar 18, 2025 via email

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

3 participants