Moh*_*mad 8 model node.js typescript
嗨,我是 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
Run Code Online (Sandbox Code Playgroud)
Hel*_*cos 16
在 NextJS 中,确保导入正确的响应类型。
import { NextApiResponse } from "next";
Run Code Online (Sandbox Code Playgroud)
小智 15
我也收到此错误,并意识到我刚刚忘记导入响应。添加导入行为我解决了这个问题。
import express, {Request, Response} from 'express';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16233 次 |
| 最近记录: |