Skip to content

Commit

Permalink
types: improve types in atom function
Browse files Browse the repository at this point in the history
  • Loading branch information
StyleShit committed Aug 22, 2024
1 parent 876fa5e commit c04b01c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/polite-terms-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'atomsphere': patch
---

Improve types in `atom` function
4 changes: 3 additions & 1 deletion src/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ type DeriveFn<T> = (get: <P>(atom: ReadableAtom<P>) => P) => T;

export function atom<T>(initialValue: DeriveFn<T>): ReadableAtom<T>;
export function atom<T>(initialValue: T): WritableAtom<T>;
export function atom<T>(initialValue: T | DeriveFn<T>) {
export function atom<T>(
initialValue: T | DeriveFn<T>,
): WritableAtom<T> | ReadableAtom<T> {
return typeof initialValue === 'function'
? createDerivedAtom(initialValue as DeriveFn<T>)
: createAtom(initialValue);
Expand Down

0 comments on commit c04b01c

Please sign in to comment.