typescript写fetch请求时候报错

如题,fetch请求直接报参数类型错误

  • 同样的代码在windows下的vscode中使用正常
  • 在Mac OS X下使用时报错

代码

function test(params?:any) {
    fetch('localhost:8003',{
        headers:{
            
        }
    })
}

报错信息

ERROR in [at-loader] ./src/index.tsx:75:28
    TS2345: Argument of type '{ headers: {}; }' is not assignable to parameter of type 'RequestInit'.
  Types of property 'headers' are incompatible.
    Type '{}' is not assignable to type 'Headers | string[][]'.
      Type '{}' is not assignable to type 'string[][]'.
        Property '[Symbol.unscopables]' is missing in type '{}'.

图片描述

在使用ant design时候也出现这种类型判断错误导致编译失败的情况

阅读 5.4k
1 个回答
  • typescript 版本不一致导致的
  • 全局安装typescript的话还是没法儿做到版本统一 所以以后将typescript安装到当前目录下 package.json记录版本信息
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进