如果在 create-react-app 專案中寫這個,那么 VS-Code 會抱怨最后一行 export { MyInterface}
// test.ts
interface MyInterface {
bazz(): void;
}
export { MyInterface }
此錯誤僅在 VS-Code 中出現 - 打字稿編譯器很好
Re-exporting a type when the '--isolatedModules' flag is provided
requires using 'export type'.ts(1205)
-----------------------------
(alias) interface MyInterface
export MyInterface
uj5u.com熱心網友回復:
錯誤資訊告訴你一切。
提供“--isolatedModules”標志時重新匯出型別需要使用“匯出型別”.ts(1205)
如果您啟用了該編譯器標志,那么您只需要更改export為export type并按預期作業:
export type { MyInterface };
代碼沙盒
根據檔案:
isolatedModules如果您撰寫的某些代碼無法被單檔案轉換程序正確解釋,則設定該標志會告訴 TypeScript 警告您。它不會改變你的代碼的行為,也不會改變 TypeScript 的檢查和發射程序的行為。
此標志強制您更明確地了解匯出。所以你只需要告訴打字稿這個匯出肯定不會在運行時通過export type.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/349280.html
下一篇:如何接受vs代碼建議的代碼
