-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for flattening of generic parameters (#336)
- Loading branch information
Showing
7 changed files
with
98 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "ts-rs-macros" | ||
version = "9.0.0" | ||
version = "9.0.1" | ||
authors = ["Moritz Bischof <[email protected]>"] | ||
edition = "2021" | ||
description = "derive macro for ts-rs" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "ts-rs" | ||
version = "9.0.0" | ||
version = "9.0.1" | ||
authors = ["Moritz Bischof <[email protected]>"] | ||
edition = "2021" | ||
license = "MIT" | ||
|
@@ -42,7 +42,7 @@ chrono = { version = "0.4", features = ["serde"] } | |
|
||
[dependencies] | ||
heapless = { version = ">= 0.7, < 0.9", optional = true } | ||
ts-rs-macros = { version = "=9.0.0", path = "../macros" } | ||
ts-rs-macros = { version = "=9.0.1", path = "../macros" } | ||
dprint-plugin-typescript = { version = "0.90", optional = true } | ||
chrono = { version = "0.4", optional = true } | ||
bigdecimal = { version = ">= 0.0.13, < 0.5", features = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use ts_rs_macros::TS; | ||
|
||
// https://github.com/Aleph-Alpha/ts-rs/issues/335 | ||
#[derive(TS)] | ||
#[ts(export, export_to = "generics/flatten/")] | ||
struct Item<D> { | ||
id: String, | ||
#[ts(flatten)] | ||
inner: D, | ||
} | ||
|
||
#[derive(TS)] | ||
#[ts(export, export_to = "generics/flatten/")] | ||
struct TwoParameters<A, B> { | ||
id: String, | ||
#[ts(flatten)] | ||
a: A, | ||
#[ts(flatten)] | ||
b: B, | ||
ab: (A, B), | ||
} | ||
|
||
#[derive(TS)] | ||
#[ts(export, export_to = "generics/flatten/")] | ||
enum Enum<A, B> { | ||
A { | ||
#[ts(flatten)] | ||
a: A, | ||
}, | ||
B { | ||
#[ts(flatten)] | ||
b: B, | ||
}, | ||
AB(A, B), | ||
} | ||
|
||
#[test] | ||
fn flattened_generic_parameters() { | ||
use ts_rs::TS; | ||
|
||
#[derive(TS)] | ||
struct Inner { | ||
x: i32, | ||
} | ||
|
||
assert_eq!(Item::<()>::decl(), "type Item<D> = { id: string, } & D;"); | ||
assert_eq!(TwoParameters::<(), ()>::decl(), "type TwoParameters<A, B> = { id: string, ab: [A, B], } & A & B;"); | ||
assert_eq!(Enum::<(), ()>::decl(), "type Enum<A, B> = { \"A\": A } | { \"B\": B } | { \"AB\": [A, B] };"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters