Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

When to use typescript specific import module in typescript?


Asked by Whitley Velez on Dec 13, 2021 TypeScript



When exporting a module using export =, TypeScript-specific import module = require ("module") must be used to import the module.
Next,
The converse is true: classic modules can be imported with the second syntax, so, in a way, the last syntax is more powerful since it is able to import all exports. For more information see the official documentation. If you have a type definition file (d.ts) for the module, you can use an import statement.
Consequently, For this to work, you need to import the module, to let TypeScript find the type information from the module’s type definition file. If you let TypeScript compile to CommonJS modules, you can also use ES6 module syntax in your TypeScript source. However, because it has no default export, you have to import it as with named exports:
Indeed,
The export keyword makes a value ( variable) defined in a file available for import in other module files. When a module is imported in another module file using import keyword, the importing file can specify the values that it wants to access from the imported module.
Besides,
When a module needs to export multiple variables, it can use so-called named exports: Another way that named exports can be done is by specifying what you want to export at the end of the module: You can import these modules in two ways. Either you import everything as one object (sometimes called namespace):