What is the purpose of using `declare` and `export` together?
See original GitHub issuesrc/Components/Footer/Footer.d.ts
declare namespace IFooter {
export interface IProps {}
}
export { IFooter };
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Documentation - Modules - TypeScript
Importing an exported declaration is done through using one of the import forms ... module into a single variable, and use it to...
Read more >export - JavaScript - MDN Web Docs
The export declaration is used to export values from a JavaScript module. Exported values can then be imported into other programs with the ......
Read more >Export and Import - The Modern JavaScript Tutorial
We can label any declaration as exported by placing export before it, be it a variable, function or a class. For instance, here...
Read more >What is export default in JavaScript ? - GeeksforGeeks
Default Exports: Default exports are useful to export only a single object, function, variable. During the import, we can use any name to...
Read more >Understanding C++ Modules: Part 2: export, import, visible ...
(The only weird one is the export keyword in the module-declaration, which is just a re-use of the keyword and does not actually...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@futuredayv
then according to the above, all you need is to remove all
import
andexport
from the file and automatically the declarations within the file will be available in the global scope.src/Components/Footer/
Footer.d.ts
src/Components/Footer/
index.tsx
As you note here, you can still use
IFooter.Iprops
without having to import it into the file. This pollute the Global namespace.@futuredayv
pros
The TypeScript code we write is in the global scope by default. If we have multiple files in a project, the variables, functions, etc. written in one file are accessible in all the other files. So its easier to use types defined in other files.
cons
Your are polluting the
global namespace
, anybody can easily override variables declared in the global scope without even knowing they are doing so. This is a dangerous space as it can lead to conflicts/erros in the code.The thing here is why use
export
anddeclare
together? There is a good reason to use this pattern?some libraries like
next/router
use it: