use-persisted-state
use-persisted-state copied to clipboard
typings file for module
I'm not 100% sure this is correct... in fact I'm only around 60% sure. But I figured I'd open a PR and you could tell me what I'm getting wrong 🙂
This will help us convert the the SessionsFM AuthProvider to TypeScript
I believe the file name needs to be index.d.ts for typescript to catch the declarations.
we should probably define the typings for Dispatch
e SetStateAction
first — might use React.Dispatch
and React.SetStateAction
the export should also use the same type on the tuple as the one provided on the createPersistedState
call
declare module 'use-persisted-state' {
function createPersistedState<T>(key: string, storage?: Storage): (initialState: T) => [T, React.Dispatch<React.SetStateAction<T>>]
export = createPersistedState
}
or directly on the hook call (to closer to useState
, hook for example):
declare module 'use-persisted-state' {
function createPersistedState(key: string, storage?: Storage): <T>(initialState: T) => [T, React.Dispatch<React.SetStateAction<T>>]
export = createPersistedState
}
i'm using a version based on useState:
declare module "use-persisted-state" {
function createPersistedState<S>(
key: string,
storage?: Storage
): (
initialState: S | (() => S)
) => [S, React.Dispatch<React.SetStateAction<S>>];
function createPersistedState<S = undefined>(
key: string,
storage?: Storage
): (
initialState: S | undefined
) => [S | undefined, React.Dispatch<React.SetStateAction<S>>];
export = createPersistedState;
}