-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
128 additions
and
0 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
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,50 @@ | ||
#![allow(unused)] | ||
|
||
use std::collections::HashMap; | ||
use ts_rs::TS; | ||
|
||
#[derive(TS)] | ||
#[ts(export)] | ||
pub struct Foo { | ||
map: HashMap<usize, Bar>, | ||
} | ||
|
||
#[derive(TS)] | ||
#[ts(export)] | ||
pub struct FooInlined { | ||
#[ts(inline)] | ||
map: HashMap<usize, Bar>, | ||
} | ||
|
||
#[derive(TS)] | ||
#[ts(export)] | ||
struct Bar { | ||
#[ts(inline)] | ||
map: HashMap<usize, Baz>, | ||
} | ||
|
||
#[derive(TS)] | ||
#[ts(export)] | ||
struct Baz { | ||
#[ts(inline)] | ||
map: HashMap<usize, String>, | ||
} | ||
|
||
|
||
#[test] | ||
#[ignore] | ||
fn issue_168() { | ||
assert_eq!( | ||
FooInlined::export_to_string().unwrap(), | ||
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\ | ||
\n\ | ||
export type FooInlined = { map: Record<number, { map: Record<number, { map: Record<number, string>, }>, }>, };" | ||
); | ||
assert_eq!( | ||
Foo::export_to_string().unwrap(), | ||
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\ | ||
import type { Bar } from \"./Bar\";\n\ | ||
\n\ | ||
export type Foo = { map: Record<number, Bar>, };" | ||
); | ||
} |
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,67 @@ | ||
#![allow(unused)] | ||
|
||
use ts_rs::TS; | ||
|
||
#[derive(TS)] | ||
#[ts(export)] | ||
struct State { | ||
a: Result<EnumWithName, String>, | ||
b: Result<EnumWithName, String>, | ||
} | ||
|
||
#[derive(TS)] | ||
#[ts(export)] | ||
struct StateInlined { | ||
#[ts(inline)] | ||
a: Result<EnumWithName, String>, | ||
#[ts(inline)] | ||
b: Result<EnumWithName, String>, | ||
} | ||
|
||
#[derive(TS)] | ||
#[ts(export)] | ||
struct StateInlinedVec { | ||
#[ts(inline)] | ||
a: Vec<Result<EnumWithName, String>>, | ||
#[ts(inline)] | ||
b: Vec<Result<EnumWithName, String>>, | ||
} | ||
|
||
#[derive(TS)] | ||
#[ts(export)] | ||
struct EnumWithName { | ||
name: String, | ||
inner: Enum | ||
} | ||
|
||
#[derive(TS)] | ||
#[ts(export)] | ||
enum Enum { | ||
A, | ||
B | ||
} | ||
|
||
#[test] | ||
fn issue_232() { | ||
println!("{}", StateInlinedVec::export_to_string().unwrap()); | ||
assert_eq!( | ||
StateInlined::export_to_string().unwrap(), | ||
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\ | ||
import type { Enum } from \"./Enum\";\n\ | ||
\n\ | ||
export type StateInlined = { \ | ||
a: { Ok : { name: string, inner: Enum, } } | { Err : string }, \ | ||
b: { Ok : { name: string, inner: Enum, } } | { Err : string }, \ | ||
};" | ||
); | ||
assert_eq!( | ||
State::export_to_string().unwrap(), | ||
"// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n\ | ||
import type { EnumWithName } from \"./EnumWithName\";\n\ | ||
\n\ | ||
export type State = { \ | ||
a: { Ok : EnumWithName } | { Err : string }, \ | ||
b: { Ok : EnumWithName } | { Err : string }, \ | ||
};" | ||
); | ||
} |