Open In App

How to import/export Modules in TypeScript ?

Last Updated : 22 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • Using the require() method:
// Exporting module
export default function_name(): void {
// Function statements
}

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

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

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads