Skip to content

Commit 17d7873

Browse files
committed
Add guide page for typescript attribute
1 parent fad83d0 commit 17d7873

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# `skip_typescript`
2+
3+
By default, Rust exports exposed to JavaScript will generate TypeScript definitions (unless `--no-typescript` is used). The `skip_typescript` attribute can be used to disable type generation per function, enum, struct, or field. For example:
4+
5+
```rust
6+
#[wasm_bindgen(skip_typescript)]
7+
pub enum MyHiddenEnum {
8+
One,
9+
Two,
10+
Three
11+
}
12+
13+
#[wasm_bindgen]
14+
pub struct MyPoint {
15+
pub x: u32,
16+
17+
#[wasm_bindgen(skip_typescript)]
18+
pub y: u32,
19+
}
20+
21+
#[wasm_bindgen]
22+
impl MyPoint {
23+
24+
#[wasm_bindgen(skip_typescript)]
25+
pub fn stringify(&self) -> String {
26+
format!("({}, {})", self.x, self.y)
27+
}
28+
}
29+
```
30+
31+
Will generate the following `.d.ts` file:
32+
33+
```ts
34+
/* tslint:disable */
35+
/* eslint-disable */
36+
export class MyPoint {
37+
free(): void;
38+
x: number;
39+
}
40+
```
41+
42+
When combined with [the `typescript_custom_section` attribute](typescript_custom_section.html), this can be used to manually specify more specific function types instead of using the generated definitions.

0 commit comments

Comments
 (0)