Merge pull request #1483 from dbrgn/typescript-optional-args

Fix optional arguments in TypeScript
This commit is contained in:
Alex Crichton
2019-05-14 12:39:35 -05:00
committed by GitHub
4 changed files with 74 additions and 27 deletions

View File

@ -1,6 +1,14 @@
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn opt_fn(_a: Option<i32>) -> Option<i32> {
/// Optional parameters followed by non-optional parameters.
/// Only the parameter _c may be marked as omittable.
pub fn opt_fn_mixed(_a: Option<i32>, _b: i32, _c: Option<i32>) -> Option<i32> {
None
}
#[wasm_bindgen]
/// Only optional parameters. All of them may be marked as omittable.
pub fn opt_fn_only(_a: Option<i32>, _b: Option<i32>, _c: Option<i32>) -> Option<i32> {
None
}

View File

@ -1,3 +1,4 @@
import * as wbg from '../pkg/typescript_tests';
const opt_fn: (a: number | undefined) => number | undefined = wbg.opt_fn;
const opt_fn_mixed: (a: number | undefined, b: number, c?: number) => number | undefined = wbg.opt_fn_mixed;
const opt_fn_only: (a?: number, b?: number, c?: number) => number | undefined = wbg.opt_fn_only;