typescript - 在 Typescript 中推断同级的类型
问题描述
我想在打字稿中实现这一点
const configuration: ResolveDeclaration = {
deps: [Foo, Bar, Baz],
resolveFn: (foo, bar, baz) => {} //<== foo, bar, baz has a type inherited in `deps` property accordingly
}
我尝试了这种方法:
export interface ResolvableLiteral<D extends readonly Injectable[]> {
deps: D;
resolveFn: (...args: D) => any;
}
但这显然不起作用,因为它不会推断传递的值,而是将其视为Injectable[]
更新:
稍后会以这种方式使用此配置:
const injectables = configuration.deps.map((token) => this.injector.get(token))
return configuration.resolveFn(...injectables)
因此,resolveFn
我想获取从依赖注入器中询问的依赖类型。
解决方案
推荐阅读
- bash - 如何从文本文件中获取每一行的第一个字段并在while循环中执行它?
- python - 在 __init__() 上调用装饰类方法
- javascript - 在 Visual Studio Code 中安装 Brain.js 时出错
- sql - PostgreSQL:如何获取 GROUP BY 的 max()?
- sql - SQL语句选择前一天的所有行和时间
- javascript - 如何将元素推送到异步函数内的数组?
- javascript - 每次页面加载后运行 JavaScript
- android - 如何在活动中使用导航条目(NavHostFragment)和数据绑定?
- dataset - 如何更改/更新数据集源文件?
- mysql - MySQL变量分配通过过程不正常工作