When I refer classes in another files, intellisense show me a bulb with the required import in VS Code. Sadly, this is not the case when path mapping is used.
"baseUrl": ".",
"paths": {
"@shared-vb/*": [
"../shared/vb/*"
]
},
"rootDirs": [
".",
"../shared"
]
If we have a class vb-sessioninfo.ts
in ../shared/vb
, we can import them cleanly using import VbSessionInfo from '@shared-vb/vb-sessioninfo'
Normally, when I type VbSessionInfo
I get an insellisense bulb with suggestions. But not in this case, I got no suggestion. The import itself works, when I type import VbSessionInfo from '@shared-vb/vb-sessioninfo'
manually.
Background: Clean, flexible imports like in C#
I want to avoid hard coded imports like import .. from '../shared/module-folder/module
. They're unflexible and can result in long nasty statements. We may have to change a lot of wrong imports if a file is moved in another folder of the filesystem. So my idea is to get some replacement for namespaces in C#. path mapping seems a good idea here: Altough it's no automatically resolving like in C#, we can define the real folders in a single place (tsconfig.json
). This speed up development and prevent me from wasting time in search/replace.
Environment
- Typescript 2.5.3
- Visual Studio Code 1.17.2 on Arch Linux
- App targets NodeJS in the latest version at time of writing (9.5.0)