How to use methods in the service layer that are not defined by interfaces when using typeScript in egg.js

since mysql, is not declared in the default Application interface in egg, it will cause an error to call directly according to the following method

 this.app.mysql.get()

to solve this problem, I used the following method

const app: any = this.app
app.mysql.get()

but if I write in this way, I think it will lose the meaning of writing typescript.

Mar.15,2021

you can write a type file yourself

import { Application } from "egg";

declare module "egg" {
    interface Application {
        mysql: any;
    }
}
Menu