How do I configure absolute paths for imports in TypeScript based React Native apps?

前端 未结 5 2054
生来不讨喜
生来不讨喜 2020-12-29 07:27

In order to avoid \'../../../../\' style relative imports in a TypeScript based React Native app, I would like to configure the app so that I can use absolute imports instea

5条回答
  •  佛祖请我去吃肉
    2020-12-29 08:32

    For anyone who uses TypeScript and just wants to use import with absolute paths without aliases.

    Assuming all of your code folders are inside of src.

    Insert "baseUrl": "src" in compilerOptions object inside tsconfig.json.

    Now you can use absolute paths in imports.

提交回复
热议问题