Skip to content

Wrong recognized This expression is not callable #35423

@MichalKalita

Description

@MichalKalita

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions