typescript - 打字稿对象声明,其中每个道具都有自己的泛型
问题描述
我正在尝试创建更动态的对象类型。现在我有以下内容:
interface MyGeneric<T> {
value: T
}
interface MyObject {
[name: string]: MyGeneric<any>;
}
但我想把它抽象成这样:
interface MyGeneric<T> {
value: T
}
interface MyObject {
[name: string]<T>: MyGeneric<T>;
}
这种语法不起作用,但我想要的是允许对象上的每个道具都有自己的泛型类型。
关于这可能是什么样子的任何建议?
解决方案
推荐阅读
- crash - 如何在 ios13 上使用 [[UIApplication sharedApplication] valueForKey:@"statusBar"] 获取 wifi 信号强度?
- c# - 具有本机集合的 Unity 作业系统比具有 C# 集合的作业系统慢
- r - 匹配两个数据框/小标题的行和列并复制值
- python - 注释字段是 str 而不是 datetime.datetime
- rstudio - 如何将Excel中的导入文件转换为R studio中的xts文件
- python - window.scrollTo() 在一个遗留项目中工作多年后突然停止工作
- javascript - 如何让我的对象重定向整个页面而不仅仅是它本身
- c++ - 使用返回 constexpr 对进行模板实例化
- angular - 为多个 observables 选择哪个 Rxjs 运算符
- javascript - 使用自己的脚本更改 iFrame 大小