Description
EDIT: since TS v4.1 baseUrl
is not longer required to use with the paths
rule, fixing this issue!
TypeScript Version: 3.7.4
Search Terms: baseUrl, autocomplete, relative path, lib, aliases, monorepo, sibling libs
Code
tsconfig.json
{
"compilerOptions": {
// ...
"baseUrl": ".",
"paths": {
"sibling-a/lib/*": ["../sibling-a/src/*"],
"sibling-b/lib/*": ["../sibling-b/src/*"]
},
},
"references": [{ "path": "../sibling-a" }, { "path": "../sibling-b" }]
}
Expected behavior: I have a monorepo with some libs and some of them uses code from sibling libs. I achieved three things I wanted: (1) to not need to build them just for TS to correctly check the imports (thanks to baseUrl/paths
config), (2) to jump into the actual definition instead of the built file (also thanks to baseUrl/paths
), (3) to TS understand the relationship between these libs (although I don't know if I configured everything correctly).
The thing is, since I'm using the baseUrl
config, any module I try to import from within the same library, but at least two folders up above the actual module will use the alias. E.g.:
// ./packages/sibling-c/src/some/path/to/file.ts
// I try to import
// ./packages/siblin-c/src/some/anotherFile.ts
// And instead of VSCode offering me
import anotherFile from '../../anotherFile';
// It will suggest something like this:
import anotherFile from 'src/anotherFile';
The problem with the alias for files withing the same lib is exactly that: they are libraries, so what I build with TS is what I publish to my private repository manager. When some service import the file with the alises it will crash because it won't understand it.
Is correct what I'm configuring/want to have?
Thank you in advance!