typescript - 打字稿无法检测相交函数中的参数类型
问题描述
我有一个可以是 Set 或 Map 的变量。其中函数的第一个参数forEach
相同,但 TypeScript 回退到any
.
declare let setOrMap: Map<string,boolean>|Set<boolean>;
setOrMap.forEach((myBool)=>{
// myBool is any 8-/
});
签名是这样的:
(method) forEach(callbackfn: ((value: boolean, key: string, map: Map<string, boolean>) => void) & ((value: boolean, value2: boolean, set: Set<boolean>) => void), thisArg: any): void
这是一个已知的错误/缺失功能(在 ts github repo 中没有找到匹配的问题)还是我错过了什么?
解决方案
推荐阅读
- python - 熊猫fillna(0),当'0'是分类时
- perl - 将数据元素及其属性从数据集中解析为数组
- android - 使用 Camera2 API 录制视频时在中心连续对焦
- mysql - SQL 通过 int | 获取行 细绳
- android - 如何确认 android 应用程序包含/不包含外部包
- c# - C# - 使用更新的数据在矩阵中打印 1 列
- google-apps-script - 为什么我的 Google Apps 脚本权限在几天后被撤销?
- c# - 不能在没有投影的条件上使用子查询
- ios - 转换整数,使其在 Swift 中有两位小数
- apache-kafka - Kafka 文档中对 min.cleanable.dirty.ratio 和 max.compaction.lag.ms 的解释可能不正确