题目描述定义了一个interface,但是检测不了类型相关代码export interface Base {
token: string; // token
source?: number; // 来源
mk: string; // 随机唯一码
ct: string; // 随机字符串
[propName: string]: any;
};export interface OrderCancel extends Base {
ids: string[];
}async cancel() { const {ctx, service} = this; const reqBody: OrderCancel = ctx.request.body;
ctx.body = await service.order.cancel(reqBody);
ctx.code = 0;
}你期待的结果是什么?实际看到的错误信息又是什么?我期望的是request.body传入的值匹配OrderCancel这个接口,对传入参数进行检验,但是请求的时候发现所有请求都可以过,没有检测类型,但是直接按照下面赋值的话,就有检测const {ctx, service} = this; const reqBody: OrderCancel = {
token: 123
};
ctx.body = await service.order.cancel(reqBody);
ctx.code = 0;求解答,求帮助
添加回答
举报
0/150
提交
取消