Skip to content
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

Not being able to compile an enum with impl #1303

Closed
Cegard opened this issue Jun 19, 2023 · 2 comments
Closed

Not being able to compile an enum with impl #1303

Cegard opened this issue Jun 19, 2023 · 2 comments

Comments

@Cegard
Copy link

Cegard commented Jun 19, 2023

Hello everybody!

I'm getting the next error wehen trying to compile an enum with an impl

error: cannot shadow already defined class 'Foo' Error: Running the wasm-bindgen CLI Caused by: Running the wasm-bindgen CLI Caused by: failed to execute 'wasm-bindgen': exited with exit status: 1

like this:

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub enum Foo {
    A,
    B
}

#[wasm_bindgen]
impl Foo {
    pub fn from(f: usize) -> Option<Foo> {
        match f {
            0 => Some(Foo::A),
            1 => Some(Foo::B),
            _ => None
        }
    }
}

wasm-pack version: 0.11.0
rustc version: 1.69.0

Regards!

@ndinata
Copy link

ndinata commented Nov 1, 2023

I believe this isn't an issue inherent in wasm-pack, but instead the underlying wasm-bindgen ? It's got to do with enums in Typescript not supporting methods. Related issue here: rustwasm/wasm-bindgen#1715, which seems to suggest exporting regular functions instead of methods.

@Cegard
Copy link
Author

Cegard commented Nov 9, 2023

You're right, it's more related with wasm-bindgen.

Thanks

@Cegard Cegard closed this as completed Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants