Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are barrels in TypeScript / Angular 2+ not recommended or best practice?

I've read several times that barrels are not recommended by Angular, but I'm not seeing that officially anywhere. And on the Angular site I see where they say they are using them.

https://angular.io/guide/glossary#B

UPDATE: In an apparent update to the Angular documentation, the page I've linked to doesn't appear to mention barrels anymore. If anyone can find where they say they use those, or an example of such usage, please comment with a link.

like image 939
BBaysinger Avatar asked Jan 26 '18 02:01

BBaysinger


People also ask

What is barrel in typescript?

A barrel is a way to rollup exports from several modules into a single convenient module. The barrel itself is a module file that re-exports selected exports of other modules.

What are barrels in angular?

A barrel, in Angular, is simply a module file which provides a centralized place for exporting components, interfaces, services etc. In turn, in your main module file, you make all imports from that single source that you defined in the barrel file.


Video Answer


1 Answers

Using Barrel exports are absolutely fine (it is just a way to simplify your import process)

If AOT compiler is not complaining about the build then it is fine.

you can read more about that here

https://medium.com/@adrianfaciu/barrel-files-to-use-or-not-to-use-75521cd18e65

https://basarat.gitbooks.io/typescript/docs/tips/barrel.html

like image 179
Jeba Prince Avatar answered Oct 14 '22 06:10

Jeba Prince