paths typescript 1

paths typescript

"compilerOptions": {
        "baseUrl": "src", // This must be specified if "paths" is.
         ...
        "paths": {
            "@app/*": ["app/*"],
            "@config/*": ["app/_config/*"],
            "@environment/*": ["environments/*"],
            "@shared/*": ["app/_shared/*"],
            "@helpers/*": ["helpers/*"]
        },
        ...

Here is what the above code is Doing:
1. baseUrl: This is the root directory of the project.
2. paths: This is where you can specify the aliases for your directories.
3. The * at the end of the path is a wildcard. It means that all the files in the directory will be included.

Now, you can import files from the aliases you’ve created.

import { Component } from ‘@angular/core’;
import { environment } from ‘@environment/environment’;
import { ConfigService } from ‘@config/config.service’;
import { SharedModule } from ‘@shared/shared.module’;
import { HelperService } from ‘@helpers/helper.service’;

Similar Posts