From c427391110e6a2fb00e71e5d7e2cb827dc7db058 Mon Sep 17 00:00:00 2001 From: Colerar <233hbj@gmail.com> Date: Thu, 10 Apr 2025 10:02:45 +0800 Subject: [PATCH] docs: update docs for `typescript_custom_section` --- .../on-rust-exports/typescript_custom_section.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/guide/src/reference/attributes/on-rust-exports/typescript_custom_section.md b/guide/src/reference/attributes/on-rust-exports/typescript_custom_section.md index 16bb3bd1b60..b2f98e0e4ac 100644 --- a/guide/src/reference/attributes/on-rust-exports/typescript_custom_section.md +++ b/guide/src/reference/attributes/on-rust-exports/typescript_custom_section.md @@ -7,12 +7,22 @@ string to the `.d.ts` file exported by `wasm-bindgen-cli` (when the ```rust #[wasm_bindgen(typescript_custom_section)] const TS_APPEND_CONTENT: &'static str = r#" - export type Coords = { "latitude": number, "longitude": number, }; - "#; ``` +It's also possible to put type definitions in a separate file: + +```rust +#[wasm_bindgen(typescript_custom_section)] +const TS_APPEND_CONTENT: &'static str = include_str!("./coords.d.ts"); +``` + +```typescript +// ./coords.d.ts +export type Coords = { "latitude": number, "longitude": number, }; +``` + The primary target for this feature is for code generation. For example, you can author a macro that allows you to export a TypeScript definition alongside the definition of a struct or Rust type.