My function accesses local/session storage, but there is a condition that it can only be called if the window is defined.
This function takes a generic args
argument which I simplified to have a type of any[]
.
While using the useSessionStorage
function, I encountered a TypeScript error:
The 'key' argument was not provided.
What's the best way to resolve this issue?
export const useStorage = ( storage: any, key: string, initialValue: any, options = {} ) => {
const { deleteKeyIfValueIs = null } = options as any
...
export const useSessionStorage = ( ...args: any[] ) =>
useStorage( typeof window !== `undefined` && sessionStorage, ...args ) // <- Error here