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

Type name collision / re-enable renaming #16

Open
Pistonight opened this issue Mar 22, 2024 · 2 comments
Open

Type name collision / re-enable renaming #16

Pistonight opened this issue Mar 22, 2024 · 2 comments

Comments

@Pistonight
Copy link

Previously #[serde(rename = "...")] can be used to rename types, but it had a problem when the type is referenced in other types madonoharu#43

However, without renaming, there could be name collisions

use serde::{Deserialize, Serialize};
use tsify::Tsify;
use wasm_bindgen::prelude::*;

mod foo {
  #[derive(Tsify, Serialize, Deserialize)]
  #[tsify(into_wasm_abi, from_wasm_abi)]
  pub struct Bar {
     ...
  }
}
mod biz {
  #[derive(Tsify, Serialize, Deserialize)]
  #[tsify(into_wasm_abi, from_wasm_abi)]
  pub struct Bar {
    ...
  }
}

becomes

export interface Bar {
  ...
}
export interface Bar {
  ...
}

To fix this, 3e81856 could be reverted to enable rename again, and madonoharu#43 can be addressed with #[tsify(type = "RenamedType")]

@siefkenj
Copy link
Owner

Hmmm...this does seem tricky. It's not nice to require users to rename there types all over the place.

Ideally, types wouldn't be global, but could be in typescript modules, but I don't think there's a way to deduce that from inside a Rust macro.

If you have name collisions, you should be able to use the namespace attribute to prevent the collision.

@siefkenj
Copy link
Owner

Apparently namespace does not work the way I thought it did...this will need different workaround.

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