TS4232: 这个表达式是 不 callable
错误信息
这个表达式是 不 callable. 类型 'X' 有否 call signatures.
快速摘要
你're trying 到 invoke 某事 as 函数, 但 TypeScript sees 它 as 非-函数类型.
为什么发生
Calling 非-函数值
类型定义 missing call signature
Union 类型哪里不 所有成员是 callable
最小示例
✗ 错误代码
const fn: string = 'hello';
fn(); // TS4232: string is not callable✓ 修复代码
const fn: () => string = () => 'hello';
fn(); // ✅ returns 'hello'更改类型到 函数类型.
如何诊断
检查类型的 表达式是 called
验证它's 函数类型
如何修复
Ensure 值是 输入 as 函数
添加 call signature 到类型
Narrow 类型到 callable 成员