TypeScript Version: All stable versions in playground (2.4.1 ... 3.7.2)
Search Terms:
This expression is not callable.
Code
const useLocalStorage = () => {
const setValue = (value: string | ((oldValue: string) => string)) => { };
// return [setValue]; // this work
return ["", setValue]; // this doesn't work
}
// const [setValue] = useLocalStorage(); // this work
const [,setValue] = useLocalStorage(); // this doesn't work
setValue((state) => "");
/*^^^^^^
This expression is not callable.
Not all constituents of type 'string | ((value: string | ((oldValue: string) => string)) => void)' are callable.
Type 'string' has no call signatures.(2349)
*/
Expected behavior:
It should works in any way of return internal function out.
Actual behavior:
This error doesn't makes sense, because if I return just setValue function will work.
Playground Link:
playground
Related Issues:
return [blah, blah] as const;
Thanks @AnyhowStep
I badly read the error message.
Const assertion or make types for function result is a solution. 馃憤
Most helpful comment
return [blah, blah] as const;