<type>api
/

index.d.ts

All
export * from './vanilla';
export * from './react';

vanilla.d.ts

Types
  • SetStateInternal

    type SetStateInternal<T> = {
        _(partial: T | Partial<T> | {
            _(state: T): T | Partial<T>;
        }["_"], replace?: false): void;
        _(state: T | {
            _(state: T): T;
        }["_"], replace: true): void;
    }["_"];
  • Get

    type Get<T, K, F> = K extends keyof T ? T[K] : F;
  • Mutate

    export type Mutate<S, Ms> = number extends Ms["length" & keyof Ms] ? S : Ms extends [
    ] ? S : Ms extends [
        [
            infer Mi,
            infer Ma
        ],
        ...infer Mrs
    ] ? Mutate<StoreMutators<S, Ma>[Mi & StoreMutatorIdentifier], Mrs> : never;
  • StateCreator

    export type StateCreator<T, Mis extends [
        StoreMutatorIdentifier,
        unknown
    ][] = [
    ], Mos extends [
        StoreMutatorIdentifier,
        unknown
    ][] = [
    ], U = T> = ((setState: Get<Mutate<StoreApi<T>, Mis>, "setState", never>, getState: Get<Mutate<StoreApi<T>, Mis>, "getState", never>, store: Mutate<StoreApi<T>, Mis>) => U) & {
        $$storeMutators?: Mos;
    };
  • StoreMutatorIdentifier

    export type StoreMutatorIdentifier = keyof StoreMutators<unknown, unknown>;
  • CreateStore

    type CreateStore = {
        <T, Mos extends [
            StoreMutatorIdentifier,
            unknown
        ][] = [
        ]>(initializer: StateCreator<T, [
        ], Mos>): Mutate<StoreApi<T>, Mos>;
        <T>(): <Mos extends [
            StoreMutatorIdentifier,
            unknown
        ][] = [
        ]>(initializer: StateCreator<T, [
        ], Mos>) => Mutate<StoreApi<T>, Mos>;
    };
Interfaces
  • StoreApi

    export interface StoreApi<T> {
        setState: SetStateInternal<T>;
        getState: () => T;
        getInitialState: () => T;
        subscribe: (listener: (state: T, prevState: T) => void) => () => void;
    }
  • StoreMutators

    export interface StoreMutators<S, A> {
    }
All
type SetStateInternal<T> = {
    _(partial: T | Partial<T> | {
        _(state: T): T | Partial<T>;
    }['_'], replace?: false): void;
    _(state: T | {
        _(state: T): T;
    }['_'], replace: true): void;
}['_'];
export interface StoreApi<T> {
    setState: SetStateInternal<T>;
    getState: () => T;
    getInitialState: () => T;
    subscribe: (listener: (state: T, prevState: T) => void) => () => void;
}
type Get<T, K, F> = K extends keyof T ? T[K] : F;
export type Mutate<S, Ms> = number extends Ms['length' & keyof Ms] ? S : Ms extends [] ? S : Ms extends [[infer Mi, infer Ma], ...infer Mrs] ? Mutate<StoreMutators<S, Ma>[Mi & StoreMutatorIdentifier], Mrs> : never;
export type StateCreator<T, Mis extends [StoreMutatorIdentifier, unknown][] = [], Mos extends [StoreMutatorIdentifier, unknown][] = [], U = T> = ((setState: Get<Mutate<StoreApi<T>, Mis>, 'setState', never>, getState: Get<Mutate<StoreApi<T>, Mis>, 'getState', never>, store: Mutate<StoreApi<T>, Mis>) => U) & {
    $$storeMutators?: Mos;
};
export interface StoreMutators<S, A> {
}
export type StoreMutatorIdentifier = keyof StoreMutators<unknown, unknown>;
type CreateStore = {
    <T, Mos extends [StoreMutatorIdentifier, unknown][] = []>(initializer: StateCreator<T, [], Mos>): Mutate<StoreApi<T>, Mos>;
    <T>(): <Mos extends [StoreMutatorIdentifier, unknown][] = []>(initializer: StateCreator<T, [], Mos>) => Mutate<StoreApi<T>, Mos>;
};
export declare const createStore: CreateStore;
export {};

react.d.ts

Types
  • ExtractState

    type ExtractState<S> = S extends {
        getState: () => infer T;
    } ? T : never;
  • ReadonlyStoreApi

    type ReadonlyStoreApi<T> = Pick<StoreApi<T>, "getState" | "getInitialState" | "subscribe">;
  • UseBoundStore

    export type UseBoundStore<S extends ReadonlyStoreApi<unknown>> = {
        (): ExtractState<S>;
        <U>(selector: (state: ExtractState<S>) => U): U;
    } & S;
  • Create

    type Create = {
        <T, Mos extends [
            StoreMutatorIdentifier,
            unknown
        ][] = [
        ]>(initializer: StateCreator<T, [
        ], Mos>): UseBoundStore<Mutate<StoreApi<T>, Mos>>;
        <T>(): <Mos extends [
            StoreMutatorIdentifier,
            unknown
        ][] = [
        ]>(initializer: StateCreator<T, [
        ], Mos>) => UseBoundStore<Mutate<StoreApi<T>, Mos>>;
    };
Functions
  • useStore

    export declare function useStore<S extends ReadonlyStoreApi<unknown>>(api: S): ExtractState<S>;
  • useStore

    export declare function useStore<S extends ReadonlyStoreApi<unknown>, U>(api: S, selector: (state: ExtractState<S>) => U): U;
All
import type { Mutate, StateCreator, StoreApi, StoreMutatorIdentifier } from './vanilla';
type ExtractState<S> = S extends {
    getState: () => infer T;
} ? T : never;
type ReadonlyStoreApi<T> = Pick<StoreApi<T>, 'getState' | 'getInitialState' | 'subscribe'>;
export declare function useStore<S extends ReadonlyStoreApi<unknown>>(api: S): ExtractState<S>;
export declare function useStore<S extends ReadonlyStoreApi<unknown>, U>(api: S, selector: (state: ExtractState<S>) => U): U;
export type UseBoundStore<S extends ReadonlyStoreApi<unknown>> = {
    (): ExtractState<S>;
    <U>(selector: (state: ExtractState<S>) => U): U;
} & S;
type Create = {
    <T, Mos extends [StoreMutatorIdentifier, unknown][] = []>(initializer: StateCreator<T, [], Mos>): UseBoundStore<Mutate<StoreApi<T>, Mos>>;
    <T>(): <Mos extends [StoreMutatorIdentifier, unknown][] = []>(initializer: StateCreator<T, [], Mos>) => UseBoundStore<Mutate<StoreApi<T>, Mos>>;
};
export declare const create: Create;
export {};

esm/index.d.mts

All
export * from './vanilla.mjs';
export * from './react.mjs';