An Interest In:
Web News this Week
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
October 16, 2021 01:53 pm GMT
Original Link: https://dev.to/danywalls/simplify-imports-in-typescript-29jo
How to simplify and organize imports in Typescript
Sometimes we have a long list of imports, with files that come from the same place, it makes our code noisy and a bit longer, something like:
import { BeersService } from './services/beers.service';import { WhiskyService } from './services/whiski.service';import { WineService } from './services/wine.service';
We can simplify it by exposing all files, from a single file, to point to all of them.
Create index.ts, (you can name as you want, but most common is index) and export all services.
export * from './beers.service';export * from './whiski.service';export * from './wine.service';
Now we can update our files, to the new path.
import { BeersService, WhiskyService, WineService } from './services/index';
The code looks clean and easy to ready because all of them comes from the same place.
Photo by Marcin Jozwiak on Unsplash
Original Link: https://dev.to/danywalls/simplify-imports-in-typescript-29jo
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To