Reputation: 1962
I'm working on a fairly large project written in TypeScript, and in many cases, a certain file/class depends on a relatively large number of imports (be it internal or external). I'm wondering if there's is a way to clean up code like this by abstracting the imports into a seperate file and then importing them all in one line in the file that needs them.
Is this possible?
Upvotes: 0
Views: 72
Reputation: 249486
You can create a module that exports types and classes from other modules and use this new module instead of the individual modules:
// all.ts
export * from './module1' // export all from module1
export { MyClass } from './module2'// export just MyClass from module2
//usage.ts
import * as all from './all'
new all.MyClass()
Upvotes: 1