Let's try to check isolated modules. When I checked Google, there is no direct context of it.
It basically means that you allow Typescript to compile modules in isolation.
But it comes from Typescript and has something to do with Typescript preferring modules over namespaces.
Modules also have a dependency on a module loader (such as
CommonJs/Require.js) or a runtime which supports ES Modules. Modules
provide for better code reuse, stronger isolation and better tooling
support for bundling.
Source 1
Using a create-react-app typescript project,
you should have installed typescript and ts-jest (or the create-react-app should handle the dependencies based on wether you ejected the app or not).
Also ts-jest
has some information about it:
By default ts-jest uses TypeScript compiler in the context of a
project (yours), with full type-checking and features. But it can also
be used to compile each file separately, what TypeScript calls an
‘isolated module’. That’s what the isolatedModules option (which
defaults to false) does.
Source 2
As soon as you use the export
command you are creating a module out of what is being exported.
If you are using ts-jest, you can add these settings without affecting your other modules, which the create-react-app will consist off.
"ts-jest": {
"isolatedModules": false
}
And checkout the ts-jest page (second source) for the pro's and con's.
import
orexport
then that file is an ES6 module. Your top example is problematic becauseit
is not defined anywhere, in a modular architecture you'd need to importit
from somewhere – apokryfos