Typescript error


error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
error TS2304: Cannot find name 'Symbol'.
error TS2339: Property 'assign' does not exist on type 'ObjectConstructor'.
error TS2339: Property 'assign' does not exist on type 'ObjectConstructor'.

有朋友在群里問我,上面這種錯誤怎么產生的

我們在剛開始學Typescript,編譯Typescript時候經常出現的錯誤

上面這種情況是因為 大多是因為沒有指定編譯js版本,因為Typescript是基於js開發的

解決方法:選擇最新版本 js ECMAScript 2017

創建 tsconfig.json    //typescript 的配置文件    更多配置詳見 列表

{
 "compilerOptions":{"module":"commonjs",
    "noImplicitAny":true,
    "removeComments":true,
    "preserveConstEnums":true,
    "sourceMap":true,
    "target":"es2017"  // <- 重點在這里 指定為最新版
 },
 "include":[
     "src/*"   //指定需要編譯的ts文件所在目錄
 ],
 "exclude":[]   //排除不需要ts編輯的文件或目錄
} 

最后直接執行   tsc    //就不會報錯了,(前提是你不要寫錯代碼哦!)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM