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.