[Technical] Add baseUrl in tsconfig.json in order to avoid relative paths
See original GitHub issueNow that the library has been migrated to typescript 🎉 I think we could use the baseUrl option
"baseUrl": "./
By doing so, we could set all the imports as absolute from that URL. So, for example, this import
import rule, { RULE_NAME } from '../../../lib/rules/no-debug';
can be now converted to
import rule, { RULE_NAME } from 'lib/rules/no-debug';
and the same applies to all import. I usually find this more readable
In addition to that, when moving files, they get updated automatically 😄
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
How to use paths in tsconfig.json? - Stack Overflow
Just specify the baseUrl, config will take care of your relative path. way to config: tsconfig.json file add the below properties.
Read more >Documentation - Module Resolution - TypeScript
Use non-relative paths when importing any of your external dependencies. ... value of baseUrl property in 'tsconfig.json' (if given path is relative, ...
Read more >How to set an absolute path in TypeScript | Towards the Cloud
This file contains the compiler options required to compile and run the project. You need to add the following properties: baseUrl and paths...
Read more >Avoid Relative Path Hell in TypeScript Backend - Medium
When I start to create a new app in TypeScript, I tend to use relative import at the beginning. But as the app...
Read more >Avoid relative path import hell in react - DEV Community
You need to configure your application to support importing modules using absolute paths. This can be done by configuring a jsconfig.json or ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok so it seems we are introducing more problems than we solve. Should we close the issue then?
I’ve maintained a TypeScript library using custom paths, and I don’t think it’s worth the effort. I spent way more time trying to fix tooling bugs than I saved by making imports absolute, and you can still simplify relative imports by just moving files around.