TypeScript Reference ยท Error Codes Worth Knowing
TypeScript error TS2349: This expression is not callable
Reference for TypeScript error TS2349: calling something that has no call signature, including unions of functions, forgotten new, and values that are not functions.
TS2349 means you wrote value(...) but the type of value has no call signatures. The message continues with the reason, for example Type 'string' has no call signatures, or, for a union, Not all constituents of type 'A | B' are callable.
The mistake is usually one of: calling a property instead of a method, calling a value that may be a string or a function, forgetting that a class needs new, or having a union of function types whose parameters cannot be combined into one call.
const label = "hello"; label(); // TS2349
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.
Syntax
| Cause | Fix |
|---|---|
| The value is not a function (property, string, number) | Remove the call parentheses, or use the right member. |
| Union with a non-function member | Narrow with typeof x === "function". |
| Union of different function types | Narrow, or give them compatible parameter types so the call can be resolved. |
A class constructor called without new |
Use new Foo(). |
Function type, {} or object |
Declare a real signature: (x: number) => string. |
| Module imported with the wrong form | Check default vs. named vs. namespace imports (see esModuleInterop). |
| Optional callback | callback?.(arg) or test it first. |
Edge case: a union of functions is callable when TypeScript can combine the parameters (it intersects them). If the parameter types are incompatible, the call becomes unresolvable and you must narrow.
Usage notes
- Check what the type says. Hovering the callee shows the type; if it is not a function type, TS2349 is correct and the fix is in the declaration.
- Namespace import misuse.
import * as express from "express"thenexpress()fails for a CommonJS function export; with interop on, use the default import. - Optional callbacks:
props.onClick?.()calls only when defined and avoids the possibly-undefined error (TS2532). - Overloaded types are callable when at least one overload matches; a mismatch gives TS2769.
- Template literal tags and
newhave their own signature kinds: calling a construct-only type as a function is this error, the reverse is TS2351 ("not constructable"). - Do not reach for
any.(value as any)()calls compile and fail at run time withTypeError: value is not a function.
Related
- TS2554
- TS2769
- TS2322
- Tutorial: Function types, Narrowing