Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

TypeScript TS2349: This expression is not callable

TS2349 means the value has no call signature at that point. Narrow unions, fix module default imports and guard optional calls instead of asserting.

~5 min readTypeScript
#typescript#ts2349#call-signatures#strict-mode
Bold white headline reading TS2349 beside a cyan call-signature plate and an amber non-callable block.

Introduction & Quick Summary

TypeScript refuses a call that JavaScript would happily attempt:

code
error TS2349: This expression is not callable. Type 'string | (() => void)' has no call signatures.

Quick answer: the value being called does not have a call signature in its declared type. Either it really is not a function at that point, or the type is too wide (a union, a namespace object, an optional member) and the compiler cannot prove it is a function without a narrowing check.

ts
const handler: string | (() => void) = getHandler(); handler(); // TS2349 if (typeof handler === "function") handler(); // ok, narrowed

The message names a type, and that type is the clue: string, {} and Function | undefined each point at a different cause. This guide covers call signatures, why unions trigger the error, and fixes that keep the code type-safe.

Core Mechanics, Signatures & Reproducible Setup

A call signature is part of a type. (a: number) => string carries one; string carries none; an object type carries one only when it is written with a call signature or a method. typeof an imported module is an object of exports, not a function.

ts
type Handler = (event: string) => void; interface Callable { (input: string): number; // call signature description: string; // properties are allowed alongside it } const parse: Callable = Object.assign((s: string) => s.length, { description: "length" }); parse("abc"); // 3

Reproduce the error in a strict project:

bash
mkdir ts2349 && cd ts2349 npm init -y >/dev/null npm i -D typescript@5 npx tsc --init --strict cat > index.ts <<'EOF' function resolve(value: string | (() => string)): string { return value(); } EOF npx tsc --noEmit # error TS2349: This expression is not callable.

The compiler narrows a union by discriminant, typeof, in, instanceof and user-defined predicates. Assignment narrowing works only when the declared type of the target is narrow enough to keep the narrowed member.

Declared typeCallable?Why
() => voidyessingle call signature
(a: string) => void or undefinedno, without a guardunion member may be undefined
{ run(): void }yes, x.run()method signature on the object
{ run: () => void }yes, x.run()property holding a function type
typeof import("./mod")nomodule object, call a named export
Functioncallable as any resultloses parameters and return type
objectnono members at all
anyyesno checking, no help

Function is a trap: it compiles, returns any and checks nothing.

ts
declare const f: Function; f("anything", 123); // compiles, no argument checking

Use an explicit signature instead, and prefer narrowing over assertion.

TechniqueExampleNarrowed inside
typeof guardtypeof v === "function"yes
truthinessif (v) v()yes for undefined and null only
in check"call" in vdiscriminated objects
assertionv as () => voidunchecked, no runtime effect
predicatefunction isFn(x: unknown): x is () => voidyes, reusable
generic constraint<T extends (...a: any[]) => any>at the boundary

Key Comparison Table

Symptom in the typeLikely causeCorrect fix
Type 'string or number' has no call signaturesvalue holds data, not a functioncall the function that produced it, or narrow
Type 'X or undefined' has no call signaturesoptional member or lookup missif (x) x() or x?.()
Type 'typeof import("...")' has no call signaturescalling a module objectcall mod.default or a named export
Type '{}' has no call signatureswidened literal or generic defaultannotate the parameter, constrain the generic
Type 'Function' has no call signatures in strict modeolder lib definitionsreplace Function with a real signature
This expression is not callable on a classcalling the class instead of a methodnew C() or obj.method()
GoalSafe patternRisk of the shortcut
Call maybe-missing callbackcallback?.(value)callback!() throws at runtime
Call union membertypeof v === "function" guardas any hides real mismatches
Type a JS utilitydeclare function util(x: string): voidrequire() returns any
Store functions in a mapRecord<string, (e: Event) => void>Record<string, Function>
Forward argumentsgeneric rest (...args: P) => Rtyped any[] loses inference
Test for callabilitytypeof x === "function"x instanceof Function crosses realms

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. A union of a function and data

ts
type Input = string | (() => string); function read(input: Input): string { if (typeof input === "function") return input(); return input; }

The guard is required because the declared type keeps both members. A common variant is a callback that may be omitted:

ts
function run(task: () => void | undefined) { task(); // TS2349: undefined has no call signatures } function runFixed(task?: () => void) { task?.(); // ok, optional call }

Optional parameters and optional properties behave the same way: the call must be guarded or use ?.().

2. Module objects, default exports and interop

ts
import * as path from "node:path"; path(); // TS2349: module namespace is not callable path.join("a", "b"); // call a member import express from "express"; const app = express(); // ok only with esModuleInterop or allowSyntheticDefaultImports

With "module": "nodenext", esModuleInterop is implied and require() of a CommonJS module yields a typed shape. In older configs, import * as express from "express"; express() fails with TS2349 exactly because a namespace object cannot be called. Use a default import, or import express = require("express") in CommonJS output.

3. Optional methods and class members

ts
class Client { send?: (body: string) => void; close(): void {} } const c = new Client(); c.send("x"); // TS2349, possibly undefined c.send?.("x"); // ok c.close(); // ok, method signature

A class method is callable through an instance, never through the class itself unless it is static. Client.close() is TS2339 while Client.close on an instance is fine.

4. Objects that look callable but are not

ts
const config = { onReady: undefined as undefined | (() => void) }; config.onReady(); // TS2349 if (config.onReady) config.onReady();

JSON.parse output is any, so it hides the problem until a typed boundary is added:

ts
interface Hooks { onReady?: () => void } const hooks = JSON.parse(raw) as Hooks; hooks.onReady?.();

Validating with a schema is stronger than asserting, but the optional call is what removes the error either way.

5. Overloads, call signatures and generics

ts
interface Parser { (input: string): string[]; (input: string[]): string; } function apply<T extends (...args: any[]) => any>(fn: T): ReturnType<T> { return fn(); }

A generic constrained to a function type is callable inside the body; a generic constrained to object or left unconstrained is not. When a factory returns T and you need to call it, constrain T:

ts
function callFactory<T extends () => unknown>(factory: T): ReturnType<T> { return factory() as ReturnType<T>; }

6. Missing or wrong type packages

ts
const yaml = require("js-yaml"); // any, no error, no safety yaml.load("a: 1");

Without @types/js-yaml, import yaml from "js-yaml" can resolve to a namespace whose members are untyped, and calls on the wrong member surface as TS2349. Install the types package, or write a minimal ambient declaration:

ts
declare module "js-yaml" { export function load(input: string): unknown; }

The error usually disappears once the declaration matches the real export style (named versus default). Use the JSON formatter to inspect a payload shape before writing the interface, and the diff checker to compare two compiler outputs after a config change.

Common Compilation/Runtime Mistakes & Version Gotchas

  • Asserting instead of narrowing. (value as () => void)() compiles and then throws value is not a function in production. The assertion is erased at runtime.
  • Assuming strict is on. Without strictNullChecks, undefined is assignable everywhere and the same code compiles; the error appears only after enabling strict mode, so CI and local configs must match.
  • Widening through a mutable variable. let fn = maybeFn; where maybeFn is (() => void) | undefined keeps the union. Reassignment inside a closure also defeats narrowing, because the value may change between guard and call.
  • Function as a parameter type. It is callable, returns any, and accepts any argument list. Library authors still ship it, so wrap it: type AnyFn = (...args: unknown[]) => unknown.
  • instanceof Function. It fails across iframes, workers and vm contexts even for real functions. typeof x === "function" does not.
  • Calling this-dependent methods detached. const { close } = client; close(); compiles if the signature matches but throws Cannot read properties of undefined. Bind it or call it as a member.
  • Version note. Since TypeScript 4.9, unlisted property access on unknown narrows more strictly, and since 5.0 decorator typing changed; both can turn previously accepted calls into TS2349 when the value came from a decorator or a satisfies expression.
  • Declaration drift. Two copies of @types/node or a monorepo with duplicate @types/react produce union types that no guard satisfies. npm ls @types/node and a single shared types array in tsconfig resolve it.

The durable fix is a type that describes what is there: a specific signature, a discriminated union or an optional member.

Official documentation: TypeScript handbook: narrowing and function types.

Official references

primary documentation

The TypeScript documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit TypeScript work — they run entirely in this browser tab, so nothing you paste leaves your device.

All TypeScript guides

More in TypeScript

All TypeScript guides

The guides filed next to this one in TypeScript, in library order.