DEV Community

Gaëtan Redin
Gaëtan Redin

Posted on • Originally published at Medium on

Simplify Typescript import

Simplify TypeScript import

How to save your time using imports?

Hey, I’m sure you have already done something like:

import { MyService } from '../../../../../core/services/my-service.service';
Enter fullscreen mode Exit fullscreen mode

Um, not sexy right?

But there is an easy solution to solve this.

Just open your tsconfig.app.json, and add paths option like this in the compilerOptions:

{
    ...
    "compilerOptions": {
        ...
        "paths": {
            "@core/*": ["src/app/core/*"],
            "@environments/*": ["src/environments/*"],
            "@feature1/*": ["src/app/feature1/*"],
            "@feature2/*": ["src/app/feature2/*"],
            ...
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

You can write as many as you want and the result will be:

import { MyService } from '@core/services/my-service.service';
Enter fullscreen mode Exit fullscreen mode

No matter where you import it now, you will have this to write.

Thanks for reading.

Learn More.

Angular for everyone: All about it

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (1)

Collapse
 
kevindoran23 profile image
KevinDoran23

you have posted really informative and valuable article . that will more beneficial for me i appreciate your work . पति पत्नी को अलग करने का टोटका

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay