Burnjs
Burnjs copied to clipboard
关 Typescript 问题
你好:
import { Controller } from "./base";
//user.ts
export default class User extends Controller {
async user() {
this.ctx.body = this.ctx.service.check.index(); // 这里仅仅爆 service 找不到,并不影响运行。
}
async userInfo() {
this.ctx.body = 'hello userinfo';
}
}
我在 base.ts 临时加了 any,也没有找到好的方法
import { BaseContext } from "koa";
interface SelfBaseContext extends BaseContext { //继承接口 BaseContext
service: any
}
export class Controller {
ctx: SelfBaseContext;
constructor(ctx: SelfBaseContext) {
this.ctx = ctx;
}
}
可以将 services 下面的模块引入来定义 service