zustand-ards
Version:
A library of simple opinionated utilities for zustand. zustand-ards are typesafe and designed to be easily added to an existing codebase to improve the experience of developing with zustand.
18 lines (15 loc) • 559 B
TypeScript
import { StoreApi } from 'zustand';
/**
* Copied from the zustand file 'react.d.ts' on line 2
*/
type ExtractState<S> = S extends {
getState: () => infer T;
} ? T : never;
/**
* Types a partial object based on the type of the original and the type of an array of keys.
*/
type PartObjFromArrOfKeys<Obj, KeyArray extends readonly (keyof Obj)[]> = {
[Key in KeyArray[number]]: Obj[Key];
};
type ReadonlyStoreApi<T> = Pick<StoreApi<T>, 'getState' | 'getInitialState' | 'subscribe'>;
export { ExtractState, PartObjFromArrOfKeys, ReadonlyStoreApi };