首页 > 解决方案 > 打字稿无法检测相交函数中的参数类型

问题描述

我有一个可以是 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 中没有找到匹配的问题)还是我错过了什么?

标签: typescript

解决方案


推荐阅读