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

Feature request: How to export multiple types to the same file #314

Closed
zhangrunzhao opened this issue Apr 25, 2024 · 4 comments
Closed

Feature request: How to export multiple types to the same file #314

zhangrunzhao opened this issue Apr 25, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@zhangrunzhao
Copy link

zhangrunzhao commented Apr 25, 2024

I only want to put two or more types into the user.ts file at the same time, is there a solution at present?

#[derive(Debug, Deserialize, TS)]
#[ts(export, export_to = "user.ts")]
struct LoginReq {
    username: String,
    pwd: String,
}


#[derive(Debug, Deserialize, TS)]
#[ts(export, export_to = "user.ts")]
struct RegisterReq {
    username: String,
    pwd: String,
}
@zhangrunzhao zhangrunzhao added the enhancement New feature or request label Apr 25, 2024
@escritorio-gustavo
Copy link
Contributor

Duplicate of #59

@escritorio-gustavo escritorio-gustavo marked this as a duplicate of #59 Apr 26, 2024
@escritorio-gustavo
Copy link
Contributor

This cannot be done currently. Setting multiple types' #[ts(export_to = "...")] to the same file path will result in the file being overwritten and contain only the last type to be exported.
Which type will be the one that remains? No way to know, that's a race condition.

Your options are:

  • Set all your export_tos to a directory path (must end in a /)
  • Set the EXPORT_TS_RS_DIR environment variable to a directory path and remove all export_tos
  • Set each type's export_to to its own, unique, file path

@escritorio-gustavo
Copy link
Contributor

escritorio-gustavo commented Apr 26, 2024

You could also try out the experimental CLI being developed in #304 (After applying one of the suggestions in the previous comment). It doesn't yet have the feature you're asking for, but it does have an option to generate an index.ts file that re-exports all your types.

If this feature gets implemented it will be through the CLI, as it is currently impossible for the library to do this on its own

@escritorio-gustavo
Copy link
Contributor

Hey @zhangrunzhao, I've been trying to figure out a way to implement this. Please take a look at #316!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants