Skip to content

Include enum values in TypeScript definitions #3239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3581,7 +3581,7 @@ impl<'a> Context<'a> {
if !variant_docs.is_empty() {
self.typescript.push_str(&variant_docs);
}
self.typescript.push_str(&format!(" {},", name));
self.typescript.push_str(&format!(" {name} = {value},"));
}
}
if enum_.generate_typescript {
Expand Down
7 changes: 7 additions & 0 deletions crates/typescript-tests/src/enums.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub enum Foo {
A = 1,
B = 3,
}
8 changes: 8 additions & 0 deletions crates/typescript-tests/src/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import * as wbg from '../pkg/typescript_tests';

const a1: wbg.Foo = wbg.Foo.A;
const a2: wbg.Foo.A = wbg.Foo.A;
const a3: wbg.Foo.A = 1;
const b1: wbg.Foo = wbg.Foo.B;
const b2: wbg.Foo.B = wbg.Foo.B;
const b3: wbg.Foo.B = 3;
1 change: 1 addition & 0 deletions crates/typescript-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod custom_section;
pub mod enums;
pub mod getters_setters;
pub mod inspectable;
pub mod omit_definition;
Expand Down