Skip to content

Commit

Permalink
i/usize types should generate bigint when in 64-bit systems
Browse files Browse the repository at this point in the history
  • Loading branch information
escritorio-gustavo committed Apr 19, 2024
1 parent d122373 commit 0de6fb2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
17 changes: 16 additions & 1 deletion ts-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@ impl_primitives! {
u8, i8, NonZeroU8, NonZeroI8,
u16, i16, NonZeroU16, NonZeroI16,
u32, i32, NonZeroU32, NonZeroI32,
usize, isize, NonZeroUsize, NonZeroIsize, f32, f64 => "number",
f32, f64 => "number",
u64, i64, NonZeroU64, NonZeroI64,
u128, i128, NonZeroU128, NonZeroI128 => "bigint",
bool => "boolean",
Expand All @@ -1022,6 +1022,21 @@ impl_primitives! {
() => "null"
}

#[cfg(target_pointer_width = "16")]
impl_primitives! {
usize, isize, NonZeroUsize, NonZeroIsize => "number"
}

#[cfg(target_pointer_width = "32")]
impl_primitives! {
usize, isize, NonZeroUsize, NonZeroIsize => "number"
}

#[cfg(target_pointer_width = "64")]
impl_primitives! {
usize, isize, NonZeroUsize, NonZeroIsize => "bigint"
}

#[rustfmt::skip]
pub(crate) use impl_primitives;
#[rustfmt::skip]
Expand Down
8 changes: 4 additions & 4 deletions ts-rs/tests/integration/issue_168.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ use ts_rs::TS;
#[derive(TS)]
#[ts(export, export_to = "issue_168/")]
pub struct Foo {
map: HashMap<usize, Bar>,
map: HashMap<u32, Bar>,
}

#[derive(TS)]
#[ts(export, export_to = "issue_168/")]
pub struct FooInlined {
#[ts(inline)]
map: HashMap<usize, Bar>,
map: HashMap<u32, Bar>,
}

#[derive(TS)]
#[ts(export, export_to = "issue_168/")]
struct Bar {
#[ts(inline)]
map: HashMap<usize, Baz>,
map: HashMap<u32, Baz>,
}

#[derive(TS)]
#[ts(export, export_to = "issue_168/")]
struct Baz {
#[ts(inline)]
map: HashMap<usize, String>,
map: HashMap<u32, String>,
}

#[test]
Expand Down

0 comments on commit 0de6fb2

Please sign in to comment.