Closed rtritto closed 3 months ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
jotai | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jul 23, 2024 9:09am |
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Does it also need a change like this?
// write-only derived atom
export function atom<Value, Args extends unknown[], Result>(
- initialValue: Value,
+ initialValue?: Value,
write: Write<Args, Result>,
-): WritableAtom<Value, Args, Result> & WithInitialValue<Value>
+): WritableAtom<Value | undefined, Args, Result> & WithInitialValue<Value | undefined>
No, I think it should be explicit, and also TS doesn't allow it.
Done
Latest commit: bd1348ff9002db031103c3b40ee6bf8a4d136330
Last updated: Jul 23, 2024 9:08am (UTC)
Playground | Link |
---|---|
React demo | https://livecodes.io?x=id/2YMSGQ3UN |
See documentations for usage instructions.
Done
@rtritto A friendly reminder
@dai-shi I need some help
Sure, but for which one? Let's first focus on the first one.
It's related to vanilla/types.test
Please add this and if you have more ideas, please add them.
diff --git a/tests/vanilla/types.test.tsx b/tests/vanilla/types.test.tsx
index e0744b8..3c89725 100644
--- a/tests/vanilla/types.test.tsx
+++ b/tests/vanilla/types.test.tsx
@@ -1,4 +1,5 @@
import { expectType } from 'ts-expect'
+import type { TypeOf } from 'ts-expect'
import { it } from 'vitest'
import { atom } from 'jotai/vanilla'
import type {
@@ -15,6 +16,15 @@ it('atom() should return the correct types', () => {
// primitive atom
const primitiveAtom = atom(0)
expectType<PrimitiveAtom<number>>(primitiveAtom)
+ expectType<TypeOf<PrimitiveAtom<number>, typeof primitiveAtom>>(true)
+ expectType<TypeOf<PrimitiveAtom<number | undefined>, typeof primitiveAtom>>(
+ false,
+ )
+
+ // primitive atom without initial value
+ const primitiveWithoutInitialAtom = atom<number | undefined>()
+ expectType<PrimitiveAtom<number | undefined>>(primitiveWithoutInitialAtom)
+ expectType<PrimitiveAtom<undefined>>(atom())
// read-only derived atom
const readonlyDerivedAtom = atom((get) => get(primitiveAtom) * 2)
Done (no other ideas)
Size Change: 0 B
Total Size: 87 kB
Related Bug Reports or Discussions
Discussion #2667
Fixes #2666
Check List
pnpm run prettier
for formatting code and docs