From 255b796b650e0c75b6f7d5922563eae109e68e97 Mon Sep 17 00:00:00 2001 From: Vlad Shcherbina Date: Fri, 24 Oct 2025 11:08:37 +0200 Subject: [PATCH 1/3] Fix the test with user-defined 'Type' type By moving it to a separate module to avoid name collision with specta::Type. A possible alternative would be to replace all occurrences of `Type` throughout `ts.rs` with qualified `specta::Type` instead of relying on `use specta::Type`, but that would touch too many lines. --- tests/tests/ts.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/tests/ts.rs b/tests/tests/ts.rs index 5036329..ca6aee8 100644 --- a/tests/tests/ts.rs +++ b/tests/tests/ts.rs @@ -407,9 +407,6 @@ fn typescript_types() { // https://github.com/specta-rs/specta/issues/374 assert_ts!(Issue374, "{ foo?: boolean; bar?: boolean }"); - - // https://github.com/specta-rs/specta/issues/386 - assert_ts!(Type, "never"); } #[derive(Type)] @@ -780,6 +777,16 @@ struct Issue374 { bar: bool, } -/// https://github.com/specta-rs/specta/issues/386 -#[derive(specta::Type)] -enum Type {} + +// https://github.com/specta-rs/specta/issues/386 +// We put this test in a separate module because the parent module has `use specta::Type`, +// so it clashes with our user-defined `Type`. +mod type_type { + #[derive(specta::Type)] + enum Type {} + + #[test] + fn typescript_types() { + assert_ts!(Type, "never"); + } +} \ No newline at end of file From e0270bf5e8b0188b59eb111a83a3011aee00e165 Mon Sep 17 00:00:00 2001 From: Vlad Shcherbina Date: Fri, 24 Oct 2025 11:09:12 +0200 Subject: [PATCH 2/3] Fix bigint error messages test --- tests/tests/bigints.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/tests/bigints.rs b/tests/tests/bigints.rs index f6632a4..c601c57 100644 --- a/tests/tests/bigints.rs +++ b/tests/tests/bigints.rs @@ -60,10 +60,9 @@ pub enum EnumWithInlineStructWithBigInt { #[test] fn test_bigint_types() { - // TODO: Fix errors - for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::(&Typescript::default()).map_err(|e| e.to_string()), Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into()))); - for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::(&Typescript::new()).map_err(|e| e.to_string()), Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into()))); - for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::(&Typescript::new().bigint(BigIntExportBehavior::Fail)).map_err(|e| e.to_string()), Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into()))); + for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::(&Typescript::default()).map_err(|e| e.to_string()), Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into()))); + for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::(&Typescript::new()).map_err(|e| e.to_string()), Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into()))); + for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::(&Typescript::new().bigint(BigIntExportBehavior::Fail)).map_err(|e| e.to_string()), Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into()))); for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::(&Typescript::new().bigint(BigIntExportBehavior::String)).map_err(|e| e.to_string()), Ok("string".into()))); for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::(&Typescript::new().bigint(BigIntExportBehavior::Number)).map_err(|e| e.to_string()), Ok("number".into()))); @@ -72,22 +71,22 @@ fn test_bigint_types() { // // // Check error messages are working correctly -> These tests second for `ExportPath` which is why they are so comprehensive assert_eq!( crate::ts::inline::(&Typescript::default()).map_err(|e| e.to_string()), - Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into()) + Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into()) ); assert_eq!( crate::ts::inline::(&Typescript::default()) .map_err(|e| e.to_string()), - Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into()) + Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into()) ); assert_eq!( crate::ts::inline::(&Typescript::default()) .map_err(|e| e.to_string()), - Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into()) + Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into()) ); assert_eq!( crate::ts::inline::(&Typescript::default()) .map_err(|e| e.to_string()), - Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into()) + Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into()) ); // TODO: This required `inline` to work better on `Option` // assert_eq!( @@ -99,11 +98,11 @@ fn test_bigint_types() { assert_eq!( crate::ts::inline::(&Typescript::default()) .map_err(|e| e.to_string()), - Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into()) + Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into()) ); assert_eq!( crate::ts::inline::(&Typescript::default()) .map_err(|e| e.to_string()), - Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into()) + Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into()) ); } From b6a3b0828eca318a8298f5afab586dde3fb752c9 Mon Sep 17 00:00:00 2001 From: Vlad Shcherbina Date: Sat, 25 Oct 2025 10:50:38 +0200 Subject: [PATCH 3/3] Regenerate compiler error messages --- tests/tests/macro/compile_error.stderr | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/tests/macro/compile_error.stderr b/tests/tests/macro/compile_error.stderr index da83a4c..dccdfaa 100644 --- a/tests/tests/macro/compile_error.stderr +++ b/tests/tests/macro/compile_error.stderr @@ -55,13 +55,11 @@ error[E0432]: unresolved import `specta::specta` note: found an item that was configured out --> $WORKSPACE/specta/src/lib.rs | + | #[cfg(all(feature = "derive", feature = "function"))] + | -------------------- the item is gated behind the `function` feature + | #[cfg_attr(docsrs, doc(cfg(all(feature = "derive", feature = "function"))))] | pub use specta_macros::specta; | ^^^^^^ -note: the item is gated here - --> $WORKSPACE/specta/src/lib.rs - | - | #[cfg(all(feature = "derive", feature = "function"))] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0601]: `main` function not found in crate `$CRATE` --> tests/macro/compile_error.rs:110:20