Skip to content

typescript_custom_section doesn't accept the result of include_str macro #2828

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

Closed
ChristianIvicevic opened this issue Mar 4, 2022 · 1 comment

Comments

@ChristianIvicevic
Copy link
Contributor

Motivation

Instead of manually writing custom typings without syntax validation or highlighting like this

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen(typescript_custom_section)]
const GAME_ACTION: &'static str = r#"
export type GameAction =
  | { type: "ToggleRotation"; value: boolean }
  | { type: "ResizeWindow"; width: number; height: number };
"#;

Proposed Solution

I'd prefer to extract the custom typings into a separate TS file and embed it using the following:

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen(typescript_custom_section)]
const GAME_ACTION: &'static str = include_str!("./custom-typings.ts");

But this is currently not supported and causes the following error message: Expected a string literal to be used with #[wasm_bindgen(typescript_custom_section)].

@scallaway
Copy link

I am too running into this problem, with anything that isn't supplied directly to the constant as r#""#.

Would be great to see if #3115 can get merged as that seems to fix this problem entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants