Namespaces:
The namespace is used for logical grouping of functionalities. A namespace can include interfaces, classes, functions and variables to support a single or a group of related functionalities.
A namespace can be created using the namespace keyword followed by the namespace name. All the interfaces, classes etc. can be defined in the curly brackets { }.
Syntax:
How can we use namespace?
In this example, we have a namespace named studentcal in file studentcalc.ts. We want to use the feeCalc function in another program. That’s why export keyword should use before the desire function.
Now we want to use the studentcal namespace as well as feeCalc function to calculate a value in a new program app.ts using the reference just like below code.
If we run this app.ts using the following command we will get an error indicates “can’t find studentcal”.
To solve this problem, we have to combine this two files studentcalc.ts and app.ts. A file named out.js. will be created if we command this line-
We got a new file named out.js. Then we have to run this out.js and that will solve the problem.
Happy Coding!!!!!