Skip to content

how to explicitly type functions? #3471

Closed Answered by Liamolucko
scarf005 asked this question in Q&A
Discussion options

You must be logged in to vote

There are two ways you can go about doing this: manually writing out the function definition with #[wasm_bindgen(typescript_custom_section] or using #[wasm_bindgen(typescript_type)].

If you want to use #[wasm_bindgen(typescript_custom_section], you'll need to first apply #[wasm_bindgen(skip_typescript)] to your function so that wasm-bindgen's automatically-generated TypeScript for the function doesn't conflict with your hand-written one.

Alternatively, you can create some imported JS types which don't actually add any functionality over JsValue, but have #[wasm_bindgen(typescript_type)] applied to them to set what type they map to in TypeScript:

#[wasm_bindgen]
extern "C" {
    // note th…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@scarf005
Comment options

@Liamolucko
Comment options

Answer selected by scarf005
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants