From 4941de8cb93514d4cf3a4a8ae5ad33820e54bac5 Mon Sep 17 00:00:00 2001 From: ssi02014 Date: Fri, 26 Jan 2024 00:44:16 +0900 Subject: [PATCH 1/2] refactor: refactoring SetAtom type --- src/react/useAtom.ts | 2 +- src/react/useSetAtom.ts | 6 +++--- src/vanilla/atom.ts | 6 ++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/react/useAtom.ts b/src/react/useAtom.ts index 19373c6b1b..4588151549 100644 --- a/src/react/useAtom.ts +++ b/src/react/useAtom.ts @@ -8,7 +8,7 @@ import type { import { useAtomValue } from './useAtomValue.ts' import { useSetAtom } from './useSetAtom.ts' -type SetAtom = (...args: Args) => Result +type SetAtom = (...args: Args) => Result type Options = Parameters[1] diff --git a/src/react/useSetAtom.ts b/src/react/useSetAtom.ts index f7c360936e..6bb5a16131 100644 --- a/src/react/useSetAtom.ts +++ b/src/react/useSetAtom.ts @@ -6,14 +6,14 @@ import type { } from '../vanilla.ts' import { useStore } from './Provider.ts' -type SetAtom = (...args: Args) => Result +type SetAtom = (...args: Args) => Result type Store = ReturnType type Options = { store?: Store } -export function useSetAtom( +export function useSetAtom( atom: WritableAtom, options?: Options, ): SetAtom @@ -23,7 +23,7 @@ export function useSetAtom>( options?: Options, ): SetAtom, ExtractAtomResult> -export function useSetAtom( +export function useSetAtom( atom: WritableAtom, options?: Options, ) { diff --git a/src/vanilla/atom.ts b/src/vanilla/atom.ts index b2cfcba268..05022b88e6 100644 --- a/src/vanilla/atom.ts +++ b/src/vanilla/atom.ts @@ -5,9 +5,7 @@ type Setter = ( ...args: Args ) => Result -type SetAtom = ( - ...args: A -) => Result +type SetAtom = (...args: Args) => Result /** * setSelf is for internal use only and subject to change without notice. @@ -93,7 +91,7 @@ export function atom( const key = `atom${++keyCount}` const config = { toString: () => key, - } as WritableAtom & { init?: Value } + } as WritableAtom & Partial> if (typeof read === 'function') { config.read = read as Read> } else { From 1eb63f21b3f862881239e8147083d6a30de6c4d8 Mon Sep 17 00:00:00 2001 From: ssi02014 Date: Fri, 26 Jan 2024 01:45:47 +0900 Subject: [PATCH 2/2] revert: revert the SetAtom type inside an atom --- src/react/useAtom.ts | 4 ++-- src/vanilla/atom.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/react/useAtom.ts b/src/react/useAtom.ts index 4588151549..9cebe9a1ee 100644 --- a/src/react/useAtom.ts +++ b/src/react/useAtom.ts @@ -12,7 +12,7 @@ type SetAtom = (...args: Args) => Result type Options = Parameters[1] -export function useAtom( +export function useAtom( atom: WritableAtom, options?: Options, ): [Awaited, SetAtom] @@ -35,7 +35,7 @@ export function useAtom>( options?: Options, ): [Awaited>, never] -export function useAtom( +export function useAtom( atom: Atom | WritableAtom, options?: Options, ) { diff --git a/src/vanilla/atom.ts b/src/vanilla/atom.ts index 05022b88e6..b2cfcba268 100644 --- a/src/vanilla/atom.ts +++ b/src/vanilla/atom.ts @@ -5,7 +5,9 @@ type Setter = ( ...args: Args ) => Result -type SetAtom = (...args: Args) => Result +type SetAtom = ( + ...args: A +) => Result /** * setSelf is for internal use only and subject to change without notice. @@ -91,7 +93,7 @@ export function atom( const key = `atom${++keyCount}` const config = { toString: () => key, - } as WritableAtom & Partial> + } as WritableAtom & { init?: Value } if (typeof read === 'function') { config.read = read as Read> } else {