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

Question: Can the generated index.ts export the other types? #81

Closed
gluax opened this issue Aug 28, 2024 · 5 comments · Fixed by #87 or #85
Closed

Question: Can the generated index.ts export the other types? #81

gluax opened this issue Aug 28, 2024 · 5 comments · Fixed by #87 or #85

Comments

@gluax
Copy link

gluax commented Aug 28, 2024

Is there a way to have our custom types exported from the index.ts file somehow?
Just a QoL question I'm wondering if I can minimize imports like `import type { RpcError } from "./bindings/RpcError.ts";

image

For instance, if I wanted that RpcError exported from that index file for whatever reason.

I tried:
image

Curious if this is possible!

@epatters
Copy link
Contributor

epatters commented Oct 12, 2024

I agree that it would be useful to have this built in. As a workaround, I created a top-level index.ts that re-exports QubitServer plus other things I want, like this:

export * from "./src"; // Directory that qubit exports type defs to

export type { JsonValue } from "./src/serde_json/JsonValue";
export type { RpcError } from "./src/RpcError";

@andogq
Copy link
Owner

andogq commented Dec 2, 2024

I've had a bit of a play around with this, and managed to get something simple enough working.

I'm foreseeing the a potential issue if the same type name is used in multiple places, as the current type exporting setup looses the 'namespaced' nature of Rust modules. For example, src/file_a.rs could export MyStruct, available at crate::file_a::MyStruct, whilst src/file_b.rs could export a different MyString, available at crate::file_b::MyStruct. This setup would cause a conflict with them both being imported and exported from the TS file as type MyStruct.

This can be solved with the #[ts(rename = "..")] option however, but it's something worth being aware of.

@andogq andogq closed this as completed in #87 Dec 2, 2024
andogq added a commit that referenced this issue Dec 2, 2024
Re-export all types within `index.ts`.

Closes #81
andogq added a commit that referenced this issue Dec 2, 2024
# Version Updates

Merging this PR will release new versions of the following packages
based on your change files.




# @qubit-rs/client

## [0.4.5]
- b6ef950 Bump dependencies



# @qubit-rs/svelte

## [0.0.6]
- b6ef950 Bump dependencies
### Dependencies

- Upgraded to `@qubit-rs/client@0.4.5`



# qubit

## [0.10.1]
- 6998257 Alter router type generation to re-export all types. (close
#81)
- 88ef762 (#84) Update `ts-rs` to 10.1.0 (thanks @epatters)
@andogq
Copy link
Owner

andogq commented Dec 2, 2024

Give qubit@0.10.2 a try, this should be solved in there.

@gluax
Copy link
Author

gluax commented Dec 2, 2024

This worked thanks so much!

@epatters
Copy link
Contributor

epatters commented Dec 3, 2024

Works for me too. Thank you!

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 a pull request may close this issue.

3 participants