Import Shortcuts

In this lesson, you will discuss how to use a simplified importation of a module.

What is an import shortcut?

TypeScript’s configuration can create shortcuts to specific areas of the code. A shortcut can be useful in a situation where many imports are deep in another branch of the code which requires a lot of navigating; for example /../../../../....

Configuration

To set up a shortcut, TypeScript’s configuration must have a baseUrl in the tsconfig.json. Then, it’s possible to add many shortcuts. Each of the shortcuts go in the paths list and are relative to the baseUrl. The definition of each path contained is a keys-values list, for which the key is the pattern to look for when importing and the value is the location to look for in the actual TypeScript file.

The configuration can look like the following:

Get hands-on with 1200+ tech skills courses.