我正在使用 TypeScript 开发一个 NodeJS 项目。但是我不知道如何app.ts通过使用类来运行文件。如何在没有 new 关键字的情况下运行 Root 类?这就是我想说的。应用程序// Expressimport { application as app } from 'express';// Controllersimport { UserController } from './controllers/user.controller'export class App { constructor(userController: UserController) { console.log("App is running"); console.log("UserController url path is : ", userController.getUrlPath); } run(): void { app.listen(3000, function () { console.log('App is running on port 3000!'); }); }}根目录import { App } from "../app";export class Root { constructor(application: App) { application.run(); }}如何在没有 new 关键字的情况下运行 Root 类?这就是我想说的。因为它必须通过依赖注入获取其构造函数的参数实例。编译器启动代码:ts-node-dev --respawn --transpileOnly ./app/root.ts此代码尝试运行 root.ts 文件的代码。有一个 Root 类,但没有创建的类对象。因此,没有可运行的类或方法。
添加回答
举报
0/150
提交
取消