Does ES6 / 7 have the keyword `declare`?

I recently studied ES6, and this led to the fact that I used Babylon a lot. Being a curious type, I started looking at the Babel Github repository to find out how they built this awesome tool, and I know if I can somehow contribute.

However, I came across this file and it says everything as declare class BabelNodeSourceLocation {} , and the file ends in .js.

This confused me a lot, and now I'm wondering if there is a declare keyword in JavaScript that I did not know about, or is it just syntax specific to Babel? All of my Google searches did not return anything.

Update: Entering the code in Babel REPL has failed. Babel simply ignored the code and did not give the equivalent output of ES5. It also did not cause errors.

+7
javascript ecmascript-6 babeljs
source share
2 answers

and the file ends with .js.

These days, this does not mean :-)

I am wondering if there is a declare keyword in JavaScript that I did not know about

No no.

Or is it just Babel-specific syntax?

Not. This is the type of ad declaration for Flow typechecker.

+6
source share

Using a stream, you can declare a global class that allows you to refer to the class type anywhere in your project. This does not affect the runtime code and does not affect granny output.

Example from the docs :

 declare class URL { constructor(urlStr: string): URL; toString(): string; static compare(url1: URL, url2: URL): boolean; }; 

And then in your project, you can refer to the URL as a class type.

Similarly, you can declare other global types, modules, functions, variables. A good way to organize them.

+2
source share

All Articles