2020/03/16

[TypeScript] 解決 TS2300: Duplicate identifier 'IteratorResult' 錯誤問題

markdown 今天在做 VS Code 套件編譯時出現以下錯誤訊息: `Duplicate identifier 'IteratorResult'` 有 2 個 *.d.ts 檔案定義相沖突 ``` Starting compilation in watch mode... ../../../npm/node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6 - error TS2300: Duplicate identifier 'IteratorResult'. 41 type IteratorResult = IteratorYieldResult | IteratorReturnResult; ~~~~~~~~~~~~~~ node_modules/@types/node/index.d.ts:74:11 74 interface IteratorResult { } ~~~~~~~~~~~~~~ 'IteratorResult' was also declared here. node_modules/@types/node/index.d.ts:74:11 - error TS2300: Duplicate identifier 'IteratorResult'. 74 interface IteratorResult { } ~~~~~~~~~~~~~~ ../../../npm/node_modules/typescript/lib/lib.es2015.iterable.d.ts:41:6 41 type IteratorResult = IteratorYieldResult | IteratorReturnResult; ~~~~~~~~~~~~~~ 'IteratorResult' was also declared here. Found 2 errors. Watching for file changes. ``` ### 解決方法 在 `tsconfig.json` 的 `compilerOptions` 區塊加上以下設定, 再重新執行編譯 透過直接跳過 Library 的檢查, 因為它不在我程式碼的控制範圍內, 把它排除即可 ``` "skipLibCheck": true, ```

沒有留言: