4.6 Importing legacy external modules

In the preceding recipe, we learned how to declare legacy external modules. In this recipe, we will learn how to consume already declared legacy external modules.

Getting Ready

All you need to implement in this recipe is an installation of TypeScript 2.0 or higher.

How to do it

We can import a legacy external module using the following syntax:

import arrays = require('./arrays');

How it works

When we use an import statement without curly brackets like the preceding one:

import arrays = require('./arrays');

The module export is automatically assigned to the variable in the import statement. This means that the value of the arrays variable in the preceding line of code will be the value of the default export in the arrays module:

arrays.first([5, 4, 3, 2, 1], 3);

Source Code

See also

Please refer to the preceding recipe to learn about the declaration of external legacy modules.


Shiv Kushwaha

Author/Programmer