form-atoms / form-atoms

Atomic form primitives for Jotai

Home Page:https://codesandbox.io/s/getting-started-with-form-atoms-v2-ddhgq2?file=/src/App.tsx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Field & Form atoms should be of `PrimitiveAtom` type

MiroslavPetrik opened this issue · comments

Describe the bug
Form atom is defined as Atom<...>.
The same is true for FieldAtom

in practice, jotai atom(initialValue) call returns a PrimitiveAtom which has a write method.

To Reproduce
try setting a field or form atom's value:

const f = fieldAtom()

// type err, f has no write method
set(f, get(f)); 

Expected behavior
The write via set should work.

Screenshots
image

  • Version: 3.2.4

Additional context
Other atoms could use the PrimitiveAtom in type definitions. e.g.

Field atoms are intentionally not writable

Do you see it as a footgun?
Shouldn't the types reflect the reality present in javascript? Now the type only hides the write method, but it is there.

Last, what about simplifying the types of the writable atoms mentioned in additional context?

No, the types should reflect the intention of the API. There's absolutely no reason anyone should be touching the internals. If you're messing with them you should definitely be warned by the type checker. It's up to you if you ignore it, but I'm openly signaling I don't care about breaking anything for you.

Not changing anything.