#![allow(dead_code)] use ts_rs::TS; #[derive(TS)] #[ts(export_to = "imports/ts_rs_test_type_a.ts")] pub struct TestTypeA { value: T, } #[derive(TS)] #[ts(export_to = "imports/ts_rs_test_type_b.ts")] pub struct TestTypeB { value: T, } #[derive(TS)] #[ts(export_to = "imports/")] pub enum TestEnum { C { value: TestTypeB }, A1 { value: TestTypeA }, A2 { value: TestTypeA }, } #[test] fn test_def() { // The only way to get access to how the imports look is to export the type and load the exported file TestEnum::export_all().unwrap(); let text = std::fs::read_to_string(TestEnum::default_output_path().unwrap()).unwrap(); let expected = match (cfg!(feature = "format"), cfg!(feature = "import-esm")) { (true, true) => concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n", "import type { TestTypeA } from \"./ts_rs_test_type_a.js\";\n", "import type { TestTypeB } from \"./ts_rs_test_type_b.js\";\n", "\n", "export type TestEnum = { \"C\": { value: TestTypeB } } | {\n", " \"A1\": { value: TestTypeA };\n", "} | { \"A2\": { value: TestTypeA } };\n", ), (true, false) => concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n", "import type { TestTypeA } from \"./ts_rs_test_type_a\";\n", "import type { TestTypeB } from \"./ts_rs_test_type_b\";\n", "\n", "export type TestEnum = { \"C\": { value: TestTypeB } } | {\n", " \"A1\": { value: TestTypeA };\n", "} | { \"A2\": { value: TestTypeA } };\n", ), (false, true) => concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n", "import type { TestTypeA } from \"./ts_rs_test_type_a.js\";\n", "import type { TestTypeB } from \"./ts_rs_test_type_b.js\";\n", "\n", "export type TestEnum = { \"C\": { value: TestTypeB, } } | { \"A1\": { value: TestTypeA, } } | { \"A2\": { value: TestTypeA, } };", "\n", ), (false, false) => concat!( "// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.\n", "import type { TestTypeA } from \"./ts_rs_test_type_a\";\n", "import type { TestTypeB } from \"./ts_rs_test_type_b\";\n", "\n", "export type TestEnum = { \"C\": { value: TestTypeB, } } | { \"A1\": { value: TestTypeA, } } | { \"A2\": { value: TestTypeA, } };", "\n", ), }; assert_eq!(text, expected); }