I don't understand what means the word ambient
in the following sentence:
A function implementation cannot be declared in an ambient context.
I'm not sure to understand the general meaning of the word, (English isn't my maternal language) and if there is a specific meaning here I don't get it as well.
I've tried to understand in my maternal language but couldn't get it in this context. It's something like current context
I'd say but it doesn't work out.
The message appeared because I was trying to declare
a class, which cannot be declared, only module
can. I've fixed it but still don't understand the meaning of the error message here.
In Typescript, Ambient in refers to the declarations used to inform a compiler that the actual piece of code exists in a different place. For example, a developer might want to write a third-party library in plain JS using jQuery or Angular.
With TypeScript 3.7, TypeScript added support for generating . d. ts files from JavaScript using JSDoc syntax. This set up means you can own the editor experience of TypeScript-powered editors without porting your project to TypeScript, or having to maintain .
Ambience : the character and atmosphere of a place.
.
TypeScript declaration files exist to tell the compiler of the environment in which it is running. Hence the word ambient context. You can only do declarations in a declaration context and not implementations.
E.g. if you have some awesomeLibrary
declared in a raw JS file that TypeScript does not know about the following will error:
awesomeLibrary = 123; // Error: `awesomeLibrary` is not defined
So you can declare it in an ambient context and now TypeScript will be fine:
declare var awesomeLibrary: any; awesomeLibrary = 123; // allowed
More on ambient declarations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With