So what are our options when we want to split code into multiple files.
Now actually we have three options for that.
The first option would be to simply write multiple code files multiple types good files types good will
then automatically compile all code files in the source directory and manually import to compiled JavaScript
files into H2 Mel.
That is an option and for some projects this might be just right.
But you would have to manage all these imports manually which can be cumbersome and error prone and
when using certain types of features you also give up type support.
If some type is defined in file a and you use it in file B and type doesn't know about this connection.
That's why this is not really a great option for bigger projects.
Instead for bigger projects we have two main options.
We have namespace and file bundling for example.
Now namespace is a type could feature a syntax feature you can add special code to your code to use
this feature and it allows you to basically group CODE TO GATHER below a namespace and then import namespace
into other files so you can have a namespace per file for example.
Import a number file into yet the number of file and tap into that namespace which lives in a number
of file from that importing file and we'll see that in practice in case that's not entirely clear typescript
does not only support that.
It also bundles the files together into one file.
So Dad you India and write code in multiple files which are compiled but they are then imported into
Java so that you have less imports to manage and you don't need to manually manage different imports
and then h html file.
Now an alternative to name basis and arguably the more important and modern alternative is to use iOS
6 imports and exports also known as iOS 6 modules because it turns out that totally detached from typescript
modern JavaScript has a solution for this problem as well because you have this problem not just in
types of projects but in any bigger javascript project.
Modern Java stripped out of the box supports import and export statements which allows to stay to which
file depends on which other file and then you have all these individual files but you don't need to
manage imports manually instead browsers.
Modern browsers do that they understand it and automatically download and run files a number of file
depends on you use the import export syntax for that and typescript all the supports this so therefore
you can use different types good without any issues you will compile per file but you only need one
script import because as I just mentioned modern browsers know how to then fetch all our dependencies
and you'll also see dad in action in this core section here.
Now one important note here with Dad we technically will end up with multiple files still and whilst
we won't have to manage the imports manually the script imports we still have some disadvantages because
of that because every failure depending on needs to be downloaded separately which means more HDTV requests
hands on and therefore you can bundle files together to work on multiple files during development but
ship a single file for production but you need third party tools for that.
For example Westpac and I will show you how that works as well but in a separate section where we will
have a look at Westpac and typescript and why we use it and how we use it.
So for now let's use these two approaches in their basic form and let's see how we can improve our code
by splitting it across multiple files.