Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified Args type #2367

Merged
merged 4 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/react/useAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
import { useAtomValue } from './useAtomValue.ts'
import { useSetAtom } from './useSetAtom.ts'

type SetAtom<Args extends any[], Result> = (...args: Args) => Result
type SetAtom<Args extends unknown[], Result> = (...args: Args) => Result
Copy link
Contributor Author

@ssi02014 ssi02014 Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, Args extends unknown[] is already used in many places. 🤗


type Options = Parameters<typeof useAtomValue>[1]

Expand Down
6 changes: 3 additions & 3 deletions src/react/useSetAtom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import type {
} from '../vanilla.ts'
import { useStore } from './Provider.ts'

type SetAtom<Args extends any[], Result> = (...args: Args) => Result
type SetAtom<Args extends unknown[], Result> = (...args: Args) => Result
type Store = ReturnType<typeof useStore>

type Options = {
store?: Store
}

export function useSetAtom<Value, Args extends any[], Result>(
export function useSetAtom<Value, Args extends unknown[], Result>(
atom: WritableAtom<Value, Args, Result>,
options?: Options,
): SetAtom<Args, Result>
Expand All @@ -23,7 +23,7 @@ export function useSetAtom<AtomType extends WritableAtom<any, any[], any>>(
options?: Options,
): SetAtom<ExtractAtomArgs<AtomType>, ExtractAtomResult<AtomType>>

export function useSetAtom<Value, Args extends any[], Result>(
export function useSetAtom<Value, Args extends unknown[], Result>(
atom: WritableAtom<Value, Args, Result>,
options?: Options,
) {
Expand Down
6 changes: 2 additions & 4 deletions src/vanilla/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ type Setter = <Value, Args extends unknown[], Result>(
...args: Args
) => Result

type SetAtom<Args extends unknown[], Result> = <A extends Args>(
...args: A
) => Result
type SetAtom<Args extends unknown[], Result> = (...args: Args) => Result

/**
* setSelf is for internal use only and subject to change without notice.
Expand Down Expand Up @@ -93,7 +91,7 @@ export function atom<Value, Args extends unknown[], Result>(
const key = `atom${++keyCount}`
const config = {
toString: () => key,
} as WritableAtom<Value, Args, Result> & { init?: Value }
} as WritableAtom<Value, Args, Result> & Partial<WithInitialValue<Value>>
if (typeof read === 'function') {
config.read = read as Read<Value, SetAtom<Args, Result>>
} else {
Expand Down