Modules in Typescript

In real time projects, we'd like to place our code in a separate files.

TypeScript supports the concept of modules.

  • A module can export classes, functions and variables, and another file can import these classes functions of variables from a given module.

 

 

Import Class: when you export a given class or entity, then that makes it available for someone else to possibly import.

    • At the end  “./Customer”- Here it's based on the file name of where that class is defined, but you don't give the dots, you simply give the actual name of the file itself without the extension.
    • if they're in different directories, then you can simply give a relative directory path.

 

Export Class for Others

  • when you export a given class or entity, then that makes it available for someone else to possibly import.

 

 

 


Related Question