Open In App

How to import/export Modules in TypeScript ?

Modules are a way of organizing and structuring the code into reusable and maintainable code blocks which can be imported into any other file where we need the same kind of code. It enhances the reusability, maintainability, and readability of our code which helps to improve the web performance of the website. You can import and export the TypeScript modules in the following ways:

// Exporting module
export default function_name(): void {
// Function statements
}

// Importing module using require() method
const importedVariableName =
require('Path of the file')
// Exporting module
export default function_name(): void {
// Function statements
}

// Importing module using rimport statement
import nameWithWhichYouWantToImportFile from 'filePath';
Article Tags :