Skip to content

loadable atom doesn't have type for returned value data and error properties #2731

Answered by dai-shi
trongthanh asked this question in Bug report
Discussion options

You must be logged in to vote

export type Loadable<Value> =
| { state: 'loading' }
| { state: 'hasError'; error: unknown }
| { state: 'hasData'; data: Awaited<Value> }
is the type we are using. We generally avoid adding | undefined in all Jotai code base. So, your request is not acceptable.

If you want to loosen the type, you can work it around with type assertion:
https://stackblitz.com/edit/jotai-gmwmbz-rbdn9a?file=src%2FApp.tsx
It's not very cute though.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@thanhtran-ct
Comment options

@dai-shi
Comment options

Answer selected by trongthanh
@trongthanh
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
3 participants