Skip to content

Commit

Permalink
Update & format documentation (#252)
Browse files Browse the repository at this point in the history
* document `#[ts(tag)]` and `#[ts(as)]`, reformat documentation

* fix line breaks in README.md

* put cargo features in a table

* Fix typo in readme

* Document change to export_to made in #250

* Add missing newline

* Explain flatten

* Document #[ts(untagged)] on enum variants

* Document #[ts(rename_all = ..)] on enum variants

* Add missing newline

* Change interface to type

* Link to mentioned items

* Run cargo readme

* Document TS::DOCS

* Improve TS::ident so it doesn't panic

* document TypeList

---------

Co-authored-by: Gustavo <[email protected]>
  • Loading branch information
NyxCode and escritorio-gustavo authored Mar 7, 2024
1 parent 3a667d4 commit 7fc4945
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 155 deletions.
74 changes: 22 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
ts-rs
</h1>
<p align="center">
generate typescript interface/type declarations from rust types
generate typescript type declarations from rust types
</p>

<div align="center">
Expand Down Expand Up @@ -59,67 +59,37 @@ struct User {
When running `cargo test`, the TypeScript bindings will be exported to the file `bindings/User.ts`.

### features
- generate interface declarations from rust structs
- generate type declarations from rust structs
- generate union declarations from rust enums
- inline types
- flatten structs/interfaces
- flatten structs/types
- generate necessary imports when exporting to multiple files
- serde compatibility
- generic types
- support for ESM imports

### cargo features
- `serde-compat` (default)
| **Feature** | **Description** |
|:-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| serde-compat | **Enabled by default** <br/>See the *"serde compatibility"* section below for more information. |
| format | Enables formatting of the generated TypeScript bindings. <br/>Currently, this unfortunately adds quite a few dependencies. |
| no-serde-warnings | By default, warnings are printed during build if unsupported serde attributes are encountered. <br/>Enabling this feature silences these warnings. |
| import-esm | When enabled,`import` statements in the generated file will have the `.js` extension in the end of the path to conform to the ES Modules spec. <br/> Example: `import { MyStruct } from "./my_struct.js"` |
| chrono-impl | Implement `TS` for types from *chrono* |
| bigdecimal-impl | Implement `TS` for types from *bigdecimal* |
| url-impl | Implement `TS` for types from *url* |
| uuid-impl | Implement `TS` for types from *uuid* |
| bson-uuid-impl | Implement `TS` for types from *bson* |
| bytes-impl | Implement `TS` for types from *bytes* |
| indexmap-impl | Implement `TS` for types from *indexmap* |
| ordered-float-impl | Implement `TS` for types from *ordered_float* |
| heapless-impl | Implement `TS` for types from *heapless* |
| semver-impl | Implement `TS` for types from *semver* |

Enable serde compatibility. See below for more info.
- `format`

When enabled, the generated typescript will be formatted.
Currently, this sadly adds quite a bit of dependencies.
- `chrono-impl`

Implement `TS` for types from chrono
- `bigdecimal-impl`

Implement `TS` for types from bigdecimal
- `url-impl`

Implement `TS` for types from url
- `uuid-impl`

Implement `TS` for types from uuid
- `bson-uuid-impl`

Implement `TS` for types from bson
- `bytes-impl`

Implement `TS` for types from bytes
- `indexmap-impl`

Implement `TS` for `IndexMap` and `IndexSet` from indexmap

- `ordered-float-impl`

Implement `TS` for `OrderedFloat` from ordered_float

- `heapless-impl`

Implement `TS` for `Vec` from heapless

- `semver-impl`
Implement `TS` for `Version` from semver

- `no-serde-warnings`

When `serde-compat` is enabled, warnings are printed during build if unsupported serde
attributes are encountered. Enabling this feature silences these warnings.

- `import-esm`

`import` statements in the generated file will have the `.js` extension in the end of
the path to conform to the ES Modules spec. (e.g.: `import { MyStruct } from "./my_struct.js"`)
<br/>

If there's a type you're dealing with which doesn't implement `TS`, use `#[ts(type = "..")]` or open a PR.
If there's a type you're dealing with which doesn't implement `TS`, use either
`#[ts(as = "..")]` or `#[ts(type = "..")]`, or open a PR.

### serde compatability
With the `serde-compat` feature (enabled by default), serde attributes can be parsed for enums and structs.
Expand Down
Loading

0 comments on commit 7fc4945

Please sign in to comment.