typescript - 将元素添加到打字稿 Record<>
问题描述
我有这样的记录设置:
let myRecord = Record<String, Set<String>>
如何将元素添加到记录内的集合中?我尝试了以下方法但没有成功:
let key = "key";
let stringToAdd = "stringToAdd";
myRecord[key].add(stringToAdd);
解决方案
您可以使用方括号[]
和赋值向记录添加元素。
let mySet: Set<string> = new Set();
mySet.add("stringToAdd");
let myRecord: Record<string, Set<string>> = {};
myRecord["key"] = mySet; // <--- Like this
推荐阅读
- python - 通过 Python \ Postgresql 上的抓取数据更新特定行
- asp.net-core - 无法为在 xUnit 中执行 Entity Framework Core 操作的控制器运行测试
- java - 比较 JSP 中的字符串会产生非常奇怪的错误,而不是指定原因
- c# - 使用将接口而不是具体类传递给@ChildContent 的 [CascadingParameter]
在西装外套 - c# - 在根对象上设置 EntityState.Modified 会向数据库添加任何新对象吗?
- javascript - 无法从资源文件夹获取文件路径 - Java(异常)
- algorithm - 关于月球近地点和远地点的算法
- php - 在 Laravel 7 中调用模型 [App\Category] 上的未定义关系 [products]
- java - 如何将“长”数字表示为链表中的节点 [JAVA]
- python - python函数和php转换的不同输出