Closed
Description
Currently, if you return an Option
from a function in rust, the generated .d.ts file does not reflect that the function can return undefined
. I am willing to help out if this is a desired change. 🙂
For example if you have the following rust,
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn some_number() -> usize {
1
}
#[wasm_bindgen]
pub fn some_optional_number() -> Option<usize> {
None
}
you get the following d.ts,
/* tslint:disable */
export function some_number(): number;
export function some_optional_number(): number;
But the actual return value has the type number | undefined
. if you run typescript in strict mode, it will force you to check for undefined, just like rust.
Or you could go even further and define a new type in typescript, ex:
type Option<T> = T | undefined;
export function some_optional_number(): Option<number>;
Would you be willing to merge a change like this if I send a PR? 🙂
Metadata
Metadata
Assignees
Labels
No labels