Explanation
I believe that the line /root/src/moduleB.d.ts is actually representing an ambient module declaration. Can someone confirm if I am misunderstanding this or if the documentation is incorrect?
There seems to be a misunderstanding here. The file moduleB.d.ts
does not contain an ambient module declaration. To clarify, here is an example of how an ambient module declaration looks like in TypeScript.
// exampleFile.d.ts
declare module "moduleB" {
export class b { }
}
The keyword declare
indicates that it is a ambient declaration statement.
Additional Information
Regarding the term ambient, the official documentation explains:
Ambient declarations refer to declarations that do not provide an implementation. These are typically found in .d.ts files.
Ambient declarations encompass various types of declarations, not just ambient module declarations. Therefore, a .d.ts file containing ambient declarations may not necessarily be an ambient module declaration itself.
For example, consider the following greeter.d.ts file which includes an ambient class declaration but is not considered an ambient module declaration:
// greeter.d.ts
declare class Greeter {
constructor(greeting: string);
greeting: string;
}
In a similar manner, the foobar.d.ts
file features ambient module declarations for "foo" and "bar", yet the entire file is not classified as an ambient module declaration.
// foobar.d.ts
declare module "foo" {
export function doFoo(foo: string): string;
}
declare module "bar" {
export function doBar(bar: string): string;
}
As per the referenced documentation, it states that a relative import like "./foo"
would not resolve to the ambient declaration mentioned above.
Further Resources
Take a look at: https://www.typescriptlang.org/docs/handbook/modules.html
Also, refer to: https://github.com/Microsoft/TypeScript-Handbook/issues/180
Explore more at: https://www.typescriptlang.org/docs/handbook/declaration-files/by-example.html