wasm-bindgen
wasm-bindgen copied to clipboard
typescript_custom_section doesn't accept the result of include_str macro
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)].