Skip to content

Commit dee8d6c

Browse files
Release v12
* Change empty object to emit `Record<symbol, never>` (#431) * Replace Record<string, never> with Record<symbol, never> * fix test * Make hashmap keys required unless the key is an enum (#446) Co-authored-by: Moritz Bischof <moritz.bischof1@gmail.com> * Refactor: Better handling of environment variables (#472) * setup plumbing of `Config` remove TS::export_all_to remove TS::default_output_path * adjust tests * fix test failures * fully specify $crate::Config in macros * Make Config::import_extension an Option<String> Add Config::array_tuple_limit Improve documentation Cleanup tests * re-generate README * tweak readme * update test * fix test * restructure README * bump version * emit #[automatically_derived] --------- Co-authored-by: Gustavo Shigueo <58121396+gustavo-shigueo@users.noreply.github.com>
1 parent d235252 commit dee8d6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2619
-1174
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
# master
2+
### Breaking
3+
### Features
4+
### Fixes
5+
6+
# 12.0.0
7+
### Breaking
8+
- Change generated type of unit structs to `Record<symbol, never>` ([#431](https://github.com/Aleph-Alpha/ts-rs/pull/431))
9+
- Change generated type of `HashMap` to `{ [key in K]: V }` if `K` is not an enum ([#446](https://github.com/Aleph-Alpha/ts-rs/pull/446))
10+
- Enable programmatic configuration of binding generation ([#460](https://github.com/Aleph-Alpha/ts-rs/pull/460))
11+
212
### Features
313
- Add `TS_RS_LARGE_INT` environment variable to configure binding for `i64`, `u64`, `i128`, etc. ([#448](https://github.com/Aleph-Alpha/ts-rs/pull/448))
14+
- Add support for `arrayvec` ([#469](https://github.com/Aleph-Alpha/ts-rs/pull/469))
15+
- Add support for `jiff` ([#458](https://github.com/Aleph-Alpha/ts-rs/pull/458))
416

517
### Fixes
18+
- Do not emit warning for `#[serde(borrow)]` ([#471](https://github.com/Aleph-Alpha/ts-rs/pull/471))
619
- Do not emit warning for `#[serde(crate = "..")]` ([#447](https://github.com/Aleph-Alpha/ts-rs/pull/447))
720
- Fix trait bound generation when using `#[ts(optional)]` on an `Option<Generic>` ([#454](https://github.com/Aleph-Alpha/ts-rs/pull/454))
21+
- Fix parsing of comma-separated serde attributes ([#466](https://github.com/Aleph-Alpha/ts-rs/pull/466))
822

923
# 11.1.0
1024
### Features

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 54 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ ts-rs = "11.1"
4646
```
4747

4848
```rust
49-
use ts_rs::TS;
50-
51-
#[derive(TS)]
49+
#[derive(ts_rs::TS)]
5250
#[ts(export)]
5351
struct User {
5452
user_id: i32,
@@ -57,8 +55,7 @@ struct User {
5755
}
5856
```
5957

60-
When running `cargo test` or `cargo test export_bindings`, the TypeScript bindings will be exported to the file `bindings/User.ts`
61-
and will contain the following code:
58+
When running `cargo test` or `cargo test export_bindings`, the following TypeScript type will be exported to `bindings/User.ts`:
6259

6360
```ts
6461
export type User = { user_id: number, first_name: string, last_name: string, };
@@ -67,70 +64,67 @@ export type User = { user_id: number, first_name: string, last_name: string, };
6764
### Features
6865
- generate type declarations from rust structs
6966
- generate union declarations from rust enums
70-
- inline types
71-
- flatten structs/types
67+
- works with generic types
68+
- compatible with serde
7269
- generate necessary imports when exporting to multiple files
73-
- serde compatibility
74-
- generic types
75-
- support for ESM imports
76-
77-
### cargo features
78-
| **Feature** | **Description** |
79-
|:-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
80-
| serde-compat | **Enabled by default** <br/>See the *"serde compatibility"* section below for more information. |
81-
| format | Enables formatting of the generated TypeScript bindings. <br/>Currently, this unfortunately adds quite a few dependencies. |
82-
| no-serde-warnings | By default, warnings are printed during build if unsupported serde attributes are encountered. <br/>Enabling this feature silences these warnings. |
83-
| serde-json-impl | Implement `TS` for types from *serde_json* |
84-
| chrono-impl | Implement `TS` for types from *chrono* |
85-
| bigdecimal-impl | Implement `TS` for types from *bigdecimal* |
86-
| url-impl | Implement `TS` for types from *url* |
87-
| uuid-impl | Implement `TS` for types from *uuid* |
88-
| bson-uuid-impl | Implement `TS` for *bson::oid::ObjectId* and *bson::uuid* |
89-
| bytes-impl | Implement `TS` for types from *bytes* |
90-
| indexmap-impl | Implement `TS` for types from *indexmap* |
91-
| ordered-float-impl | Implement `TS` for types from *ordered_float* |
92-
| heapless-impl | Implement `TS` for types from *heapless* |
93-
| semver-impl | Implement `TS` for types from *semver* |
94-
| smol_str-impl | Implement `TS` for types from *smol_str* |
95-
| tokio-impl | Implement `TS` for types from *tokio* |
96-
| jiff-impl | Implement `TS` for types from *jiff* |
97-
| arrayvec-impl | Implement `TS` for types from *arrayvec* |
98-
99-
<br/>
70+
- precise control over generated types
10071

101-
If there's a type you're dealing with which doesn't implement `TS`, use either
102-
`#[ts(as = "..")]` or `#[ts(type = "..")]`, or open a PR.
103-
104-
### `serde` compatability
105-
With the `serde-compat` feature (enabled by default), serde attributes can be parsed for enums and structs.
106-
Supported serde attributes:
107-
- `rename`
108-
- `rename-all`
109-
- `rename-all-fields`
110-
- `tag`
111-
- `content`
112-
- `untagged`
113-
- `skip`
114-
- `skip_serializing`
115-
- `skip_serializing_if`
116-
- `flatten`
117-
- `default`
118-
119-
Note: `skip_serializing` and `skip_serializing_if` only have an effect when used together with
120-
`#[serde(default)]`.
121-
122-
Note: `skip_deserializing` is ignored. If you wish to exclude a field
123-
from the generated type, but cannot use `#[serde(skip)]`, use `#[ts(skip)]` instead.
72+
If there's a type you're dealing with which doesn't implement `TS`, you can use either
73+
`#[ts(as = "..")]` or `#[ts(type = "..")]`, enable the appropriate cargo feature, or open a PR.
12474

125-
When ts-rs encounters an unsupported serde attribute, a warning is emitted, unless the feature `no-serde-warnings` is enabled.
126-
127-
### Environment variables
75+
### Configuration
76+
When using `#[ts(export)]` on a type, `ts-rs` generates a test which writes the bindings for it to disk.\
77+
The following environment variables may be set to configure *how* and *where*:
12878
| Variable | Description | Default |
12979
|--------------------------|---------------------------------------------------------------------|--------------|
13080
| `TS_RS_EXPORT_DIR` | Base directory into which bindings will be exported | `./bindings` |
13181
| `TS_RS_IMPORT_EXTENSION` | File extension used in `import` statements | *none* |
13282
| `TS_RS_LARGE_INT` | Binding used for large integer types (`i64`, `u64`, `i128`, `u128`) | `bigint` |
13383

84+
We recommend putting this configuration in the project's [config.toml](https://doc.rust-lang.org/cargo/reference/config.html#env) to make it persistent:
85+
```toml
86+
# <project-root>/.cargo/config.toml
87+
[env]
88+
TS_RS_EXPORT_DIR = { value = "bindings", relative = true }
89+
TS_RS_LARGE_INT = "number"
90+
```
91+
92+
To export bindings programmatically without the use of tests, `TS::export_all`, `TS::export`, and `TS::export_to_string` can be used instead.
93+
94+
### Serde Compatibility
95+
With the `serde-compat` feature (enabled by default), serde attributes are parsed for enums and structs.\
96+
Supported serde attributes: `rename`, `rename-all`, `rename-all-fields`, `tag`, `content`, `untagged`, `skip`, `skip_serializing`, `skip_serializing_if`, `flatten`, `default`
97+
98+
**Note**: `skip_serializing` and `skip_serializing_if` only have an effect when used together with
99+
`#[serde(default)]`. This ensures that the generated type is correct for both serialization and deserialization.
100+
101+
**Note**: `skip_deserializing` is ignored. If you wish to exclude a field
102+
from the generated type, but cannot use `#[serde(skip)]`, use `#[ts(skip)]` instead.
103+
104+
When ts-rs encounters an unsupported serde attribute, a warning is emitted, unless the feature `no-serde-warnings` is enabled.\
105+
We are currently waiting for [#54140](https://github.com/rust-lang/rust/issues/54140), which will improve the ergonomics arund these diagnostics.
106+
107+
### Cargo Features
108+
| **Feature** | **Description** |
109+
|:-------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
110+
| serde-compat | **Enabled by default** <br/>See the *"serde compatibility"* section below for more information. |
111+
| format | Enables formatting of the generated TypeScript bindings. <br/>Currently, this unfortunately adds quite a few dependencies. |
112+
| no-serde-warnings | By default, warnings are printed during build if unsupported serde attributes are encountered. <br/>Enabling this feature silences these warnings. |
113+
| serde-json-impl | Implement `TS` for types from *serde_json* |
114+
| chrono-impl | Implement `TS` for types from *chrono* |
115+
| bigdecimal-impl | Implement `TS` for types from *bigdecimal* |
116+
| url-impl | Implement `TS` for types from *url* |
117+
| uuid-impl | Implement `TS` for types from *uuid* |
118+
| bson-uuid-impl | Implement `TS` for *bson::oid::ObjectId* and *bson::uuid* |
119+
| bytes-impl | Implement `TS` for types from *bytes* |
120+
| indexmap-impl | Implement `TS` for types from *indexmap* |
121+
| ordered-float-impl | Implement `TS` for types from *ordered_float* |
122+
| heapless-impl | Implement `TS` for types from *heapless* |
123+
| semver-impl | Implement `TS` for types from *semver* |
124+
| smol_str-impl | Implement `TS` for types from *smol_str* |
125+
| tokio-impl | Implement `TS` for types from *tokio* |
126+
| jiff-impl | Implement `TS` for types from *jiff* |
127+
| arrayvec-impl | Implement `TS` for types from *arrayvec* |
134128

135129
### Contributing
136130
Contributions are always welcome!

e2e/dependencies/consumer/Cargo.lock

Lines changed: 11 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/dependencies/dependency1/Cargo.lock

Lines changed: 11 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)