![](/img/trans.png)
[英]Argument of type 'string | undefined' is not assignable to parameter of type 'string' - TypeScript error
[英]error Argument of type 'Set<string>' is not assignable to parameter of type 'string'
我有兩個財產:
roleIdFormIdMap: Map<string, Set<string>>;
appIdFormIdMap: Map<string, Set<string>>;
我已經在這兩個屬性上設置了值。
現在我需要檢索值:
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);
}
我會做這樣的事情來聚合集合:
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])
據我了解 Set.add 方法只接受一個參數並拒絕迭代器Set javascript
formIds
類型是Set<string> | undefined
Set<string> | undefined
,所以你不能直接調用.add
就可以了formIds?.add(???)
Set
上add
函數需要string
,所以你不能在這里傳遞everyoneFormIds
因為everyoneFormIds
類型是Set<string> | undefined
Set<string> | undefined
嘗試這個:
everyoneFormIds.forEach((id) => formIds.add(id))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.