madonoharu / tsify

A library for generating TypeScript definitions from rust code.
Apache License 2.0
300 stars 41 forks source link

Support for methods? #39

Open nappa85 opened 10 months ago

nappa85 commented 10 months ago

Probably connected to #3, let's say I have this code:

use wasm_bindgen::prelude::*;

#[derive(serde::Deserialize, tsify::Tsify)]
#[tsify(from_wasm_abi)]
pub struct Foo {
    bar: Bar,
}

#[derive(serde::Deserialize, tsify::Tsify)]
#[tsify(from_wasm_abi)]
pub struct Bar {
    inner: String,
}

#[wasm_bindgen]
impl Bar {
    pub fn foobar(self) -> bool {
        true
    }
}

#[wasm_bindgen]
pub fn foo(foo: Foo) {}

It generates this typescript:

/* tslint:disable */
/* eslint-disable */
/**
* @param {Foo} foo
*/
export function foo(foo: Foo): void;
export interface Foo {
    bar: Bar;
}

export interface Bar {
    inner: string;
}

As you can see, no trace of foobar method. Is it possible to enable methods generation?

Anyway, I can suppose that this code will result in a null pointer exception from second call to foobar, since it consumes self, and that's why I think it's related to #3