lag*_*van 4 typescript ecmascript-6 lodash typescript-typings
我们一直在旧的 TypeScript 项目中使用 lodash。现在我们正在迁移到 ES6 模块,因此用 lodash-es 替换 lodash。在lodash中,Dictionary这里声明了一个类型:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/lodash/common/common.d.ts#L247-L249
interface Dictionary<T> {
[index: string]: T;
}
Run Code Online (Sandbox Code Playgroud)
我们用它来声明一些字段,如下所示:
labTransGrouped: Dictionary<Array<ILabtransItem>>;
Run Code Online (Sandbox Code Playgroud)
lodash-es 中没有明显的替代品。我想我应该使用 TypeScript Map 之类的东西来代替。但在我的例子中,在类型声明中使用它的正确方法是什么?我在 lodash 变更日志或迁移指南中找不到任何提及,所以一定是简单的事情。
小智 6
我遇到了同样的问题。
lodash-es当然没有Dictionary类型,但它Dictionary是一个如此简单的类型,您甚至不需要自己创建。
只需将 Dictionary 类型复制到代码中的某个位置并导入即可。
export interface Dictionary<T> {
[index: string]: T;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8518 次 |
| 最近记录: |