pmndrs / jotai

👻 Primitive and flexible state management for React

Home Page:https://jotai.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Store type is not exported for createStore()

AriaFallah opened this issue · comments

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?

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.)

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.