Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关 Typescript 问题 #5

Open
liangtongzhuo opened this issue Jun 6, 2018 · 1 comment
Open

关 Typescript 问题 #5

liangtongzhuo opened this issue Jun 6, 2018 · 1 comment

Comments

@liangtongzhuo
Copy link

liangtongzhuo commented Jun 6, 2018

你好:

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;
    }
}
@hua1995116
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants