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

Store type is not exported for createStore() #2522

Closed
AriaFallah opened this issue Apr 25, 2024 · 2 comments
Closed

Store type is not exported for createStore() #2522

AriaFallah opened this issue Apr 25, 2024 · 2 comments

Comments

@AriaFallah
Copy link

Summary

Jotai doesn't export the Store type for createStore

Link to reproduction

const store: ??? = createStore()

Workaround

const store: ReturnType<typeof createStore> = createStore()

Question

Is there a reason why it's not exported?

@dai-shi
Copy link
Member

dai-shi commented Apr 25, 2024

We generally consider some types are internal, and don't export many types.
In the case of Store, we didn't even have it internally either.
I believe ReturnType<typeof createStore> is the right solution, not just a workaround, unless there's drawback. (I don't think I get "slow types" with JSR #2443, so it should be fine.)

@dai-shi dai-shi closed this as completed Apr 25, 2024
@AriaFallah
Copy link
Author

Hmm @dai-shi I'm not sure I fully understand. All return types on public functions are already part of the public API. By not exposing them, you put users in a weird spot where they cannot use the types they're already consuming in one way or another.

While it's true that you can do ReturnType<typeof createStore>, this really is a gigantic hack and a quirk of TypeScript's turing-complete type system. I don't think any non gradually typed programming languages would let you get away with returning a non-public type.

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

No branches or pull requests

2 participants