-
Notifications
You must be signed in to change notification settings - Fork 142
Description
Is your feature request related to a problem? Please describe.
Hi! I just come across this library when trying to generate ts object type for my code. It's working great overall, but I find it kind of confusing when it comes to integration with my existing wasm_bindgen generated typings. Currently the typings are placed under bindings/ and there's no direct way to have it exported to the .d.ts file generated by wasm_bindgen
Describe alternatives you've considered
I'm currently setting the export_to of all my types to index.ts, as well as adding the following custom section to make this work:
#[wasm_bindgen(typescript_custom_section)]
const TS_RS_BINDINGS: &'static str = r#"
import * as Bindings from './bindings';
export * from './bindings';
"#;So that I can use the types like
#[derive(Serialize, TS, Clone)]
#[ts(export, export_to = "index.ts")]
pub struct Foobar {
x: i32,
y: String,
}
#[wasm_bindgen(typescript_custom_section)]
const TS_FOOBAR_CALLBACK: &'static str = r#"
/** A callback providing Foobar */
export type FoobarCallback = (foobar: Bindings.Foobar) => void;
"#;
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(typescript_type = "FoobarCallback")]
pub type FoobarCallback;
}
#[wasm_bindgen]
pub fn subscribe_foobar_signal(callback: FoobarCallback) {
...
}And this also requires manually moving the bindings/ directory to the pkg/ directory by wasm-pack command. It works, but I think there can be some improvements.
Describe the solution you'd like
I think maybe allowing some global argument to set all types exporting to one file (preferably a .d.ts file) by default can be a good idea? I came across this issue #5 about .d.ts file but it seems that the feature is no longer there. Also, maybe it can be allowed to set the type directly appended to the .d.ts file generated by the wasm_bindgen, instead of creating a separate bindings/ directory?