“This is the 20th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

Unknowingly is a year of light snow……

preface

We’ve covered a lot about TS, including basic types, interfaces, types, generics, enumerations, type inference and compatibility, modules and namespaces

Today we will talk about TS, called TS module parsing process

What is module resolution

define

What is TS module parsing?

Module resolution refers to the process followed by the compiler to find the contents of an imported module

The process you follow when looking for the contents of an imported module should actually be easy to understand

For example,

Let me give you an example to help you understand

Suppose we import an A from the module moduleA, i.e. Import {a} from “moduleA”

In this example, a is the module content to import

The compiler needs to know exactly what a is, and will check the module in which it is located, the moduleA, which defines it

So the compiler has a question: “What is the structure of the moduleA?”

The following is the general process of parsing

The parsing process

1. Follow the policy to find modules

First, the compiler tries to find the file that represents the imported module

The compiler follows one of two strategies: Classic or Node. These policies tell the compiler where to look for moduleA.

2. Locate the external module declaration

If the above resolution fails and the module name is nonrelative (and in the case of “moduleA”), the compiler tries to locate an external module declaration

3. Records are incorrect

If the compiler still cannot parse the module, it logs an error.

In this case, the error might be error TS2307: Cannot find module ‘moduleA’

The final summary is as follows:

note

You may not understand that there are two parsing strategies (Classic and Node) mentioned in this article, but I’ll cover both in detail in the next article. Read on

END

That’s all for this article. If you have any questions, please point out