Why is --isolatedModules error fixed by any import?

后端 未结 3 1463
醉话见心
醉话见心 2020-12-13 08:14

In a create-react-app typescript project, I tried to write this just to test some stuff quickly:

// experiment.test.ts         


        
3条回答
  •  情歌与酒
    2020-12-13 08:39

    Typescript treats files without import/exports as legacy script files. As such files are not modules and any definitions they have get merged in the global namespace. isolatedModules forbids such files.

    Adding any import or export to a file makes it a module and the error disappears.

    Also export {} is a handy way to make a file a module without importing anything.

提交回复
热议问题