onikienko/use-chrome-storage

Add proper typing support for typescript

Darhagonable opened this issue · 1 comments

Currently the typing looks like this:

useChromeStorageLocal(key: string, initialValue?: any): [any, (value: any) => void, boolean, string];

The problem with this is that the state always is any instead of being properly typed.

Would be better it it looked something similar to this:

useChromeStorageLocal<T>(key: string, initialValue?: T): [T, (value: T) => void, boolean, string];

This would allow one to say what type the the value is using type arguments and perform proper type checking:

const [value, setValue, isPersistent, error] = useChromeStorageLocal<number>('counterLocal', 0);

console.log(value) // here value will property be seen as a number instead of any

Thank you for opening this issue.

TypeScript is not my language. May you please create PR with these fixes?