[英]error Argument of type 'Set<string>' is not assignable to parameter of type 'string'
I have two property :我有两个财产:
roleIdFormIdMap: Map<string, Set<string>>;
appIdFormIdMap: Map<string, Set<string>>;
I have set the value on both property.我已经在这两个属性上设置了值。
Now i need to retrieve the value :现在我需要检索值:
let formIds = this.props.roleIdFormIdMap.get(securityRoleId);
const everyoneFormIds = this.props.roleIdFormIdMap.get(everyoneSecurityRole);
if (formIds && everyoneFormIds) {
///how to add value , here I am getting the error Argument of type 'Set<string>' is not assignable
to parameter of type 'string'.ts(2345)
formIds.add(everyoneFormIds);
}
if (appId && appId !== this.appNoSelectionKey && formIds) {
const formIdsBasedOnApp = this.props.appIdFormIdMap.get(appId);
//same thing here , how to acheive it
formIds = _.intersectionWith(formIdsBasedOnApp, formIds, _.isEqual);
}
I would do something like this to aggregate sets:我会做这样的事情来聚合集合:
const a = new Set([1,2,3]) const b = new Set([3,4,5]) // Aggregate results from a to b a.forEach((v) => b.add(v)) console.log([...b])
To my understanding the method Set.add only admits one argument and denies iterators Set javascript据我了解 Set.add 方法只接受一个参数并拒绝迭代器Set javascript
formIds
type here is Set<string> | undefined
formIds
类型是Set<string> | undefined
Set<string> | undefined
, so you will not be directly able to call .add
on it Set<string> | undefined
,所以你不能直接调用.add
就可以了formIds?.add(???)
formIds?.add(???)
add
function on Set
takes string
, so you wont be able to pass everyoneFormIds
here because type of everyoneFormIds
is Set<string> | undefined
Set
上add
函数需要string
,所以你不能在这里传递everyoneFormIds
因为everyoneFormIds
类型是Set<string> | undefined
Set<string> | undefined
Try this:尝试这个:
everyoneFormIds.forEach((id) => formIds.add(id))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.