DEV Community

Discussion on: How to improve imports in your code

Collapse
 
hamodey85 profile image
Mohammed Almajid • Edited

You can make it much better

I use Typescript all the time and in my tsconfig I set my paths

        "paths": {

            "@core/*": ["src/core/*"],
            "@types/*": ["src/core/types/*"],
            "@config/*": ["src/core/config/*"],
            "@models/*": ["src/models/*"],
            "@middleware/*": ["src/middleware/*"],
            "@controllers/*": ["src/controllers/*"]
        }
Enter fullscreen mode Exit fullscreen mode

but in my application i have to use tsconfig-paths package

so if i want to import files from controllers i do

import { something} from "@controllers/"
Enter fullscreen mode Exit fullscreen mode

resources
npmjs.com/package/tsconfig-paths
typescriptlang.org/docs/handbook/m...
stackoverflow.com/questions/432817...

correct me if I missed something