Barrel · TypeScript Deep Dive

  • /demo ; // demo/index.ts is implied // usage baz.getBaz(); baz.setBaz(); // etc. …
  • The barrel itself is a module file that re-exports selected exports of other modules.
  • /baz.ts ; // import as a name export { baz }; // export the name
  • /demo/foo.ts ; import { Bar } from ..
  • /demo/bar.ts ; import { Baz } from ..

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.

@basarat: Documented the #Barrel pattern for #TypeScript / #JavaScript modules: 🌹

#AngularJS #ReactJS

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.

Without a barrel, a consumer would need three import statements:

Barrel · TypeScript Deep Dive

You might also like More from author

Comments are closed, but trackbacks and pingbacks are open.