javascript - 我如何在 NestJS 中从另一个类扩展一个类?
问题描述
我正在尝试从 NestJS 中的另一个类服务扩展一个类服务,并使用 DI 将其加载到第三个服务中。我得到嵌套错误:
Error: Nest can't resolve dependencies of the AlgorithmsService (?, SocketService). Please make sure that the argument Object at index [0] is available in the AlgorithmsModule context.
Potential solutions:
- If Object is a provider, is it part of the current AlgorithmsModule?
- If Object is exported from a separate @Module, is that module imported within AlgorithmsModule?
@Module({
imports: [ /* the Module containing Object */ ]
})
所以如果我检查 algorithm.service.ts
@Injectable()
export class AlgorithmsService {
constructor(public coinMakerService: CoinMakerService,
public socketService: SocketService) { }
}
在 app.module.ts
@Module({
imports: [AlgorithmsModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule { }
所以 algorithm.module.ts
@Module({
imports: [],
exports: [],
controllers: [AlgorithmsController],
providers: [
AlgorithmsService,
CoinMakerService,
CryptoService,
SocketService
]
})
export class AlgorithmsModule { }
最后,我假装 tyo 扩展的最后一个类:
@Injectable()
export class CryptoService {
constructor() { }
}
@Injectable()
export class CoinMakerService extends CryptoService {
constructor() {
super()
}
}
我不知道我是否需要声明其他任何内容。我试图将所有服务移动到一个共享模块并从顶级 app.module.ts 导入它,但我得到了同样的错误。
解决方案
解决了。问题出paths
在tsconfig.json
似乎 NestJS 与我经常使用的这个功能不太兼容。
推荐阅读
- javascript - 在 getElementsByClassName-JavaScript 给出的类似数组上使用 remove() 时出现索引问题
- sql-server - Always On:慢速复制连接会影响客户端的整体性能吗?
- html - 即使没有要滚动的内容,Xcode WKWebView HTML 内容也会滚动
- svg - SVG路径贝塞尔曲线
- python - 无法获取部署在 Flask 上的 Python 脚本的输入
- java - JUnit 5 @ParamterizedTest {arguments} 与 {argumentsWithNames} 占位符
- android - Slack 像底页对话框片段
- python - ValueError: 层序贯_10 的输入 0 与层不兼容:预期 ndim=5,发现 ndim=4。Alexnet(cnn) + LSTM
- java - 是否可以使用 Java 下载整个 YouTube 播放列表,更具体地说是 Android Studio
- java - 如何在 Java 中禁用 linting?