When you bring in a module without using a '.' or '..' prefix
For instance: import File from 'FileClass';
How does the ts compiler exactly locate the 'FileClass'
?
The documentation states
- Module names can be relative or top-level. A module name is considered relative if it begins with a single dot ('.') or double dots ('..').
- Top-level names are resolved based on the root of the conceptual module namespace.
https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#11.3.1
Therefore, 'FileClass'
must be categorized as a so called top-level
module.
However, the documentation does not provide an explanation of what constitutes a top-level
module.
My initial question is, what does the term top-level
refer to? And what exactly is a conceptual module namespace root
?
As I delved further into the documentation, I came across this statement
If the import declaration specifies a top-level module name and there are no AmbientModuleDeclaration (section 12.2) instances with a string literal matching that exact name in the program, the resolution of the name happens host-dependent manner (such as considering the name relative to the module namespace root). If a corresponding module cannot be found, an error will occur.
This explanation is quite complex for me to grasp. Can you provide a real-world example illustrating this scenario?
PS: My TypeScript version is 1.5