From 0de6fb2790e8fb269c00df7a85f8cca8b985074c Mon Sep 17 00:00:00 2001 From: Gustavo Date: Fri, 19 Apr 2024 15:34:50 -0300 Subject: [PATCH] i/usize types should generate bigint when in 64-bit systems --- ts-rs/src/lib.rs | 17 ++++++++++++++++- ts-rs/tests/integration/issue_168.rs | 8 ++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ts-rs/src/lib.rs b/ts-rs/src/lib.rs index 5eb7d0e3..8ce510f8 100644 --- a/ts-rs/src/lib.rs +++ b/ts-rs/src/lib.rs @@ -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", @@ -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] diff --git a/ts-rs/tests/integration/issue_168.rs b/ts-rs/tests/integration/issue_168.rs index d4f687e9..218dd9a9 100644 --- a/ts-rs/tests/integration/issue_168.rs +++ b/ts-rs/tests/integration/issue_168.rs @@ -7,28 +7,28 @@ use ts_rs::TS; #[derive(TS)] #[ts(export, export_to = "issue_168/")] pub struct Foo { - map: HashMap, + map: HashMap, } #[derive(TS)] #[ts(export, export_to = "issue_168/")] pub struct FooInlined { #[ts(inline)] - map: HashMap, + map: HashMap, } #[derive(TS)] #[ts(export, export_to = "issue_168/")] struct Bar { #[ts(inline)] - map: HashMap, + map: HashMap, } #[derive(TS)] #[ts(export, export_to = "issue_168/")] struct Baz { #[ts(inline)] - map: HashMap, + map: HashMap, } #[test]