Inlining Vec
, HashMap
, Option
and Result
#239
Replies: 7 comments 16 replies
-
The following is one of the ideas I proposed in #233: For This idea seems ridiculous, but think about it:
But notice that The problem is instead of stating this to be illegal (or just the same as calling name), we recursively The same is true for In fact, if Option were exported, name would return You can even test this out by creating your own Option and Result enums: #[derive(TS)]
#[ts(export, untagged)]
enum MyOption<T> {
Some(T),
None
}
#[derive(TS)]
#[ts(export, rename_all = "lowercase")]
enum MyResult<T, E> {
Ok(T),
Err(E),
}
#[derive(TS)]
#[ts(export)]
struct MyStruct {
not_inlined_option: MyOption<String>,
#[ts(inline)]
inlined_option: MyOption<String>,
not_inlined_result: MyResult<EnumWithName, String>,
#[ts(inline)]
inlined_result: MyResult<EnumWithName, String>,
}
#[test]
fn check() {
assert_eq!(
MyStruct::decl(),
"type MyStruct = { not_inlined_option: MyOption<string>, inlined_option: string | null, not_inlined_result: MyResult<EnumWithName, string>, inlined_result: { \"ok\": EnumWithName } | { \"err\": string }, };"
)
} |
Beta Was this translation helpful? Give feedback.
-
I think your analysis here is correct to some extent. The handeling for To make them behave like every other type, we could just define However, it seems like there's an other bug lurking here: #[derive(TS)]
#[ts(export)]
struct Test {}
#[derive(TS)]
#[ts(export)]
enum MyOption<T> {
Some(T),
None
}
#[derive(TS)]
#[ts(export)]
struct Outer {
a: MyOption<Test>
} generates this TS, in which the import for // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
import type { MyOption } from "./MyOption";
export type Outer = { a: MyOption<Test>, }; I'm not 100% sure about this, but fixing this bug might allow us to keep our current special-handeling of |
Beta Was this translation helpful? Give feedback.
-
Alright, now that #241 has resolved the problem with generics not being imported, we need to get back to how we are supposed to deal with the inlining of transparent types ( |
Beta Was this translation helpful? Give feedback.
-
Absolutely! After thinking about your analysis a bit, I now totally agree that the recursive inlining the impls currently do is a no-go since it breaks the dependency tracking outright. Let's look at It currently returns |
Beta Was this translation helpful? Give feedback.
-
Also, out of the four (Vec, HashMap, Option, Result), Result is different than the other 3.
|
Beta Was this translation helpful? Give feedback.
-
@NyxCode, I have pushed a commit that should fix the problem by making all 4 of those impls more closely resemble |
Beta Was this translation helpful? Give feedback.
-
This has been successfully resolved by merging #241 |
Beta Was this translation helpful? Give feedback.
-
The four types in the title (as well as anything that uses
impl_shadow!
to defer to them) cause the#[ts(inlne)]
attribute to generate invalid import statements, as shown in #168 and #232. This discussion is meant to decide how to tackle this problem.Beta Was this translation helpful? Give feedback.
All reactions