How to use paths in tsconfig.json?
Check this similar solutions with asterisk
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"src/types/*"
]
},
You can use combination of baseUrl
and paths
docs.
Assuming root is on the topmost src
dir(and I read your image properly) use
// tsconfig.json
{
"compilerOptions": {
...
"baseUrl": ".",
"paths": {
"lib/*": [
"src/org/global/lib/*"
]
}
}
}
For webpack
you might also need to add module resolution. For webpack2
this could look like
// webpack.config.js
module.exports = {
resolve: {
...
modules: [
...
'./src/org/global'
]
}
}
This can be set up on your tsconfig.json file, as it is a TS feature.
You can do like this:
"compilerOptions": {
"baseUrl": "src", // This must be specified if "paths" is.
...
"paths": {
"@app/*": ["app/*"],
"@config/*": ["app/_config/*"],
"@environment/*": ["environments/*"],
"@shared/*": ["app/_shared/*"],
"@helpers/*": ["helpers/*"]
},
...
Have in mind that the path where you want to refer to, it takes your baseUrl as the base of the route you are pointing to and it's mandatory as described on the doc.
The character '@' is not mandatory.
After you set it up on that way, you can easily use it like this:
import { Yo } from '@config/index';
the only thing you might notice is that the intellisense does not work in the current latest version, so I would suggest to follow an index convention for importing/exporting files.
https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping