typescript - relative import cannot resolve to an ambient module -


according typescript documentation (https://www.typescriptlang.org/docs/handbook/module-resolution.html):

a relative import resolved relative importing file , cannot resolve ambient module declaration.

but also:

for example, import statement import { b } "./moduleb" in /root/src/modulea.ts result in attempting following locations locating "./moduleb":

/root/src/moduleb.ts /root/src/moduleb.tsx /root/src/moduleb.d.ts /root/src/moduleb/package.json (if specifies "typings" property) /root/src/moduleb/index.ts /root/src/moduleb/index.tsx /root/src/moduleb/index.d.ts" 

the line /root/src/moduleb.d.ts seems me ambient module declaration used resolve relative import "./moduleb" -> documentation denies does.

am missing here or documentation wrong?

short answer

the line /root/src/moduleb.d.ts seems me ambient module declaration... missing here or documentation wrong?

you missing here. moduleb.d.ts not ambient module declaration. here example of file contains ambient module declaration of moduleb.

// somefile.d.ts   declare module "moduleb" {     export class b { } } 

the declare keyword specifies ambient declaration.

some details

about word ambient, the documentation says:

we call declarations don’t define implementation “ambient”. typically, these defined in .d.ts files.

ambient declarations include not limited ambient module declarations. .d.ts file contains ambient declarations not ambient module declaration , not contain ambient module declaration.

for instance, following greeter.d.ts file contains ambient class declaration, not ambient module declaration.

// greeter.d.ts  declare class greeter {     constructor(greeting: string);     greeting: string; } 

the following foobar.d.ts file contains 2 ambient module declarations of "foo" , "bar", file not ambient module declaration.

// foobar.d.ts  declare module "foo" {            export function dofoo(foo: string): string; }  declare module "bar" {     export function dobar(bar: string): string; } 

the documentation cited states relative import of "./foo" not resolve above ambient declaration of module.

further details

see: https://www.typescriptlang.org/docs/handbook/modules.html

see also: https://github.com/microsoft/typescript-handbook/issues/180

see also: https://www.typescriptlang.org/docs/handbook/declaration-files/by-example.html


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -