Confusion in typescript interface object detection

topic description

defines an interface, but cannot detect the type

related codes

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;
  }

what result do you expect? What is the error message actually seen?

what I expect is that the value passed in by request.body matches the interface OrderCancel to verify the incoming parameters. However, during the request, it is found that all requests can be passed, and there is no detection type. However, if the value is assigned directly according to the following, there will be detection

.
const {ctx, service} = this;
    const reqBody: OrderCancel = {
        token: 123
    };
    ctx.body = await service.order.cancel(reqBody);
    ctx.code = 0;

ask for answers, ask for help

Dec.27,2021

const {ctx, service} = this;
where does the this of this code come from?

Menu