denoland / deno_bindgen

Write high-level Deno FFI libraries in Rust.
MIT License
287 stars 28 forks source link

Bug: Runtime type error when return String in non_blocking mode #76

Closed kayac-chang closed 2 years ago

kayac-chang commented 2 years ago

Problem

Rust Source Code

#[deno_bindgen(non_blocking)]
fn say_hello() -> String {
    String::from("Hello, kirby")
}

Deno Source Code

import { say_hello } from "./bindings/bindings.ts";
say_hello();

Throw Error below 😢

error: TS2345 [ERROR]: Argument of type 'Promise<Uint8Array>' is not assignable to parameter of type 'Uint8Array'.
  Type 'Promise<Uint8Array>' is missing the following properties from type 'Uint8Array': BYTES_PER_ELEMENT, buffer, byteLength, byteOffset, and 28 more.
  return decode(result)
                ~~~~~~

TS2773 [ERROR]:     Did you forget to use 'await'?
      return decode(result)
                    ~~~~~~

Possible Solution

take a look #77

littledivy commented 2 years ago

Fixed in https://github.com/denoland/deno_bindgen/pull/77