mirror of
https://github.com/xazukx/ts-rs.git
synced 2026-11-19 22:40:25 +00:00
Handle case where TypePath::qself is Some (#310)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use syn::{
|
||||
AngleBracketedGenericArguments, Attribute, Field, GenericArgument, Ident, PathArguments,
|
||||
AngleBracketedGenericArguments, Attribute, Field, GenericArgument, Ident, PathArguments, QSelf,
|
||||
Result, ReturnType, Type, TypeArray, TypeGroup, TypeParen, TypePath, TypePtr, TypeReference,
|
||||
TypeSlice, TypeTuple,
|
||||
};
|
||||
@@ -232,7 +232,11 @@ fn replace_underscore(ty: &mut Type, with: &Type) {
|
||||
replace_underscore(elem, with);
|
||||
}
|
||||
}
|
||||
Type::Path(TypePath { path, qself: None }) => {
|
||||
Type::Path(TypePath { path, qself }) => {
|
||||
if let Some(QSelf { ty, .. }) = qself {
|
||||
replace_underscore(ty, with);
|
||||
}
|
||||
|
||||
for segment in &mut path.segments {
|
||||
match &mut segment.arguments {
|
||||
PathArguments::None => (),
|
||||
|
||||
@@ -2,14 +2,28 @@
|
||||
|
||||
use ts_rs::TS;
|
||||
|
||||
trait Bar {
|
||||
type Baz;
|
||||
}
|
||||
|
||||
impl Bar for String {
|
||||
type Baz = i32;
|
||||
}
|
||||
|
||||
#[derive(TS)]
|
||||
#[ts(export)]
|
||||
struct Foo {
|
||||
#[ts(optional, as = "Option<_>")]
|
||||
my_optional_bool: bool,
|
||||
|
||||
#[ts(as = "<_ as Bar>::Baz")]
|
||||
q_self: String,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
assert_eq!(Foo::inline(), "{ my_optional_bool?: boolean, }");
|
||||
assert_eq!(
|
||||
Foo::inline(),
|
||||
"{ my_optional_bool?: boolean, q_self: number, }"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user