Closed JLarky closed 2 years ago
Thanks for reporting. Does v1.6.4 break? https://github.com/pmndrs/jotai/blob/v1.6.4/src/core/useAtomValue.ts#L14 has the recursive definition.
https://ci.codesandbox.io/status/pmndrs/jotai/pr/1399 Try "Local Install Instructions" ☝️
https://ci.codesandbox.io/status/pmndrs/jotai/pr/1399 Try "Local Install Instructions" ☝️
I didn't test it thoroughly but it doesn't seem like it fixed it
-jotai@^1.6.7:
- version "1.6.7"
- resolved "https://registry.yarnpkg.com/jotai/-/jotai-1.6.7.tgz#d5bdc747b66e369f1d1e859dad8bcda85acb946f"
- integrity sha512-MxAm86FYHm6asU3O1hbTKOWpPMP5oI8zNlgFRpZBB85cX79psF2eRb7ZqdGewOgYUUUKAlzZ+sH0IM7Pea6MkA==
+"jotai@https://pkg.csb.dev/pmndrs/jotai/commit/d1038b1a/jotai":
+ version "1.8.2"
+ resolved "https://pkg.csb.dev/pmndrs/jotai/commit/d1038b1a/jotai#c3fdb1f7abd48f44dd29d1b39ff5975cbce57657"
Thanks for reporting. Does v1.6.4 break? https://github.com/pmndrs/jotai/blob/v1.6.4/src/core/useAtomValue.ts#L14 has the recursive definition.
yes, I tested this, on ts 4.0 I see 1.6.3 works fine, and 1.6.4 fails
I just tested locally with CRA, and it seems to work fine.
yeah, it works for me in some other simpler configurations, but I have monorepo with multiple typescript versions and I'm using microbundle
. So it would be hard to make a proper reproduction. We can probably call it "fixed" for a general case though :)
yeah, sounds like your env doesn't handle "typeVersions"
well.
I'll add a commit in #1399, which may ease a workaround on your env.
Yay, it's working. jotai-issue-1398-2.zip
yeah, sounds like your env doesn't handle
"typeVersions"
well. I'll add a commit in #1399, which may ease a workaround on your env.
Sorry for the confusion. I looked a bit more into it. Both 4.1 fix and 4.5 fix actually worked but I was getting some random error that I mistook for this original useAtom
error. So I can confirm that both fixes actually work in ts 4.0. (I might look more into that other error as a separate issue ;) so...)
But I agree that using built-in Awaited
is of course a better way moving forward :)
What happens:
useAtom
returns the value with typeany
. Why:declare type Awaited<T> = T extends Promise<infer V> ? Awaited<V> : T;
this recursive declaration from useAtom is not supported in ts 4.0 What I have tested: I have ts 4.0 project and I noticed that it stopped building with jotai 1.7 and 1.8 but works in 1.6 I also tested jotai 1.8 on different versions using typescript playground and found that it works in 4.1 and up and doesn't work (i.e. returnsany
) in 4.0 and downTS playground link: https://www.typescriptlang.org/play?ts=4.0.5#code/JYWwDg9gTgLgBAbzgQxhEAaOBXAzgUwEE0Q4BfOAMynTgHIArCGZYOgbgChOBjCAO1zwaQ-FADCyHgAt8cALwoSACjp0AlF14ChOAsXQBGaACYFcZeoUA+RJzhw+g+AG0AblkoBdc3iIqRGDFJGXx1ezgAekiHWIA9AH4ItwA6NAAZCAB3YOQCS04yTiA