UNPKG

1.21 kBTypeScriptView Raw
1export declare type SetStateAction<Value> = Value | ((prev: Value) => Value);
2export declare type Getter = <Value>(atom: Atom<Value>) => Value;
3export declare type Setter = <Value, Update>(atom: WritableAtom<Value, Update>, update: Update) => void;
4export declare type Scope = symbol | string | number;
5export declare type SetAtom<Update> = undefined extends Update ? (update?: Update) => void | Promise<void> : (update: Update) => void | Promise<void>;
6export declare type OnUnmount = () => void;
7export declare type OnMount<Update> = <S extends SetAtom<Update>>(setAtom: S) => OnUnmount | void;
8export declare type Atom<Value> = {
9 toString: () => string;
10 debugLabel?: string;
11 scope?: Scope;
12 read: (get: Getter) => Value | Promise<Value>;
13};
14export declare type WritableAtom<Value, Update> = Atom<Value> & {
15 write: (get: Getter, set: Setter, update: Update) => void | Promise<void>;
16 onMount?: OnMount<Update>;
17};
18export declare type WithInitialValue<Value> = {
19 init: Value;
20};
21export declare type PrimitiveAtom<Value> = WritableAtom<Value, SetStateAction<Value>>;
22export declare type AnyAtom = Atom<unknown>;
23export declare type AnyWritableAtom = WritableAtom<unknown, unknown>;