首页 > 解决方案 > UnhandledPromiseRejectionWarning:ReferenceError:未定义字符串

问题描述

我的 Express JS API 端点中有一个简单的条件,我使用 typeof 检查输入的值是否为字符串。

if (!name || typeof name != 'string') {
    res.status(400).json({
      success: false,
      message: 'Please enter the meal name correctly! (Hint: name must be a string)'
    });
}

问题是它不断抛出这个错误:UnhandledPromiseRejectionWarning: ReferenceError: string is not defined. 我的代码有什么问题?

提前致谢。

标签: javascriptnode.jsexpress

解决方案


推荐阅读