鍍金池/ 問答/Linux  HTML/ typescript寫fetch請求時候報錯

typescript寫fetch請求時候報錯

如題,fetch請求直接報參數(shù)類型錯誤

  • 同樣的代碼在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時候也出現(xiàn)這種類型判斷錯誤導致編譯失敗的情況

回答
編輯回答
雅痞
  • typescript 版本不一致導致的
  • 全局安裝typescript的話還是沒法兒做到版本統(tǒng)一 所以以后將typescript安裝到當前目錄下 package.json記錄版本信息
2017年9月13日 01:39