node.js - 此表达式不可调用。类型 'Number' 没有调用签名

标签 node.js typescript model

嗨,我是 Typescript 的新手,我有一个对象类型变量,其中可能是来自不同类型或嵌套对象的不同值。现在我的问题是,如何为这个对象定义一个模型,以便在调用不同的键时不会遇到示例错误?

例如:

export class Controller {
protected static response(res: Response, statusCode: number = 200, data: any, user: string = '', dev: string = '', code: number = 200, result: string = 'success'){
    res.status(statusCode).send({
        data: data,
        message: {
            user: '',
            dev: ''
        },
        code: 403,
        result: 'Error'
    })
}


 ERROR: res.status ---> This expression is not callable. Type 'Number' has no call signatures

最佳答案

我也收到此错误,并意识到我刚刚忘记导入响应。添加导入行为我解决了这个问题。

import express, {Request, Response} from 'express';

关于node.js - 此表达式不可调用。类型 'Number' 没有调用签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60463324/

相关文章:

node.js - 找不到模块 app.js?

typescript - 如何让 TypeScript 忽略导入?

Typescript 泛型扩展类和接口(interface)

algorithm - 将网格划分为四面体?

c# - 使用 DataAnnotations 和 DataType 进行电子邮件模型验证

node.js - Angular 2/4 Typescript 数组内容未更新

node.js - 如何在没有硬编码的情况下在 Expressjs 中设置虚拟主机?

node.js - 无法安装 "@angular/cli"

typescript - 导出模型并在模板上使用

node.js - Sequelize 迁移 NodeJS