Burnjs icon indicating copy to clipboard operation
Burnjs copied to clipboard

关 Typescript 问题

Open liangtongzhuo opened this issue 6 years ago • 1 comments

你好:

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

liangtongzhuo avatar Jun 06 '18 10:06 liangtongzhuo

可以将 services 下面的模块引入来定义 service

hua1995116 avatar Oct 21 '19 12:10 hua1995116