-
Notifications
You must be signed in to change notification settings - Fork 117
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
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
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