小编lag*_*van的帖子

ES6 中的 Lodash 字典替换

我们一直在旧的 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 变更日志或迁移指南中找不到任何提及,所以一定是简单的事情。

typescript ecmascript-6 lodash typescript-typings

4
推荐指数
1
解决办法
8518
查看次数