-
Notifications
You must be signed in to change notification settings - Fork 97
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
typings file for module #32
base: develop
Are you sure you want to change the base?
Conversation
declare module 'use-persisted-state' { | ||
function createPersistedState<T>(key: string, storage: Storage): (initialState: T) => [S, Dispatch<SetStateAction<S>>]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to make storage
optional via storage?: Storage
, since it has a default
@@ -0,0 +1,4 @@ | |||
declare module 'use-persisted-state' { | |||
function createPersistedState<T>(key: string, storage: Storage): (initialState: T) => [S, Dispatch<SetStateAction<S>>]; | |||
export = createPersistedState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is the default export, I had to use export default createPersistedState
. Without that, it would work fine, but TS was complaining about synthetic default imports
I believe the file name needs to be index.d.ts for typescript to catch the declarations. |
we should probably define the typings for the export should also use the same type on the tuple as the one provided on the 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 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;
} |
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