Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading ts_rs to 10.0.0 #5163

Merged
merged 4 commits into from
Nov 6, 2024
Merged

Upgrading ts_rs to 10.0.0 #5163

merged 4 commits into from
Nov 6, 2024

Conversation

dessalines
Copy link
Member

Was able to remove some custom derives for this also.

Unfortunately this does require adding ts(optional) directives for every Option type that derives ts::TS. Context Aleph-Alpha/ts-rs#364

I went through the generated types and verified that none output null | . I've added a woodpecker test for this also.

@dessalines dessalines marked this pull request as ready for review November 3, 2024 01:49
fn transparent() -> bool {
true
}
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one's no longer necessary, as ts-rs now has a URL derive impl.

@@ -39,19 +40,3 @@ impl From<String> for SensitiveString {
SensitiveString(t)
}
}

#[cfg(feature = "full")]
impl TS for SensitiveString {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore either.

FederationError {
#[cfg_attr(feature = "full", ts(optional))]
error: Option<FederationError>,
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to make these named structs, because tuple structs don't support the derives.

@Nutomic
Copy link
Member

Nutomic commented Nov 5, 2024

This is really extremely verbose now. As these ts(optional) annoations are only for Typescript code style and irrelevant for Rust, it would make more sense to fix the generated TS code with a linter.

@dessalines
Copy link
Member Author

I agree I really don't like it, but I don't think there's a way around it, and its what ts-rs is recommending now (see that linked thread above).

It could be done with some post-generated regex, but my regex skills aren't good enough to do inline conversions from field: Something | null to field?: Something

@Nutomic
Copy link
Member

Nutomic commented Nov 5, 2024

I assume there would be some existing tool which can rewrite this.

@dessalines
Copy link
Member Author

I looked into eslints, and there doesn't seem to be a good way to enforce it. I'll test some other things out though.

@dessalines dessalines marked this pull request as draft November 5, 2024 19:27
@dessalines
Copy link
Member Author

I checked and there's really no way around it. This is just something we have to accept with ts-rs.

@Nutomic Nutomic merged commit df664d9 into main Nov 6, 2024
2 checks passed
@SleeplessOne1917 SleeplessOne1917 deleted the upgrade_ts_rs branch November 6, 2024 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants