TypeScript Version: 2.2.0
Expected behavior:
Instead of auto-importing local files absolute starting from the root of the project, it should auto-import relatively to the file. I personally never saw someone importing their files with an absolute path.
Actual behavior:
When I auto-import a local file, it will import that file starting from the root of my project.
I import with a non-relative path whenever the import target is not a logical sibling. It is easier to maintain when you reorganize submodules as none of the imports have to change.
I see your point. Probably there will be 2 groups of people on this discussion. So why not make it configurable? In my case, I'm working with VS Code and then it would be nice to just have a setting typescript.relativeImport which could be set to true or false.
While some configuration setting could be nice, I think a better approach would be to have the pop-up show both possibilities for the user to choose. Then a setting could override this behavior.
I would like this feature as well, since in my convoluted test setup I have to use relative paths and manually changing them every time is a nuisance.
In my angular app typescript always auto imports like import { } from 'app/...'
I find it interesting. My baseUrl is set to baseUrl: "." which should be app's parent folder. Anyway, after each auto import VS Code starts to complain it cannot find the module. I'm up for relative path flag in settings.
funny thing, I just noticed that in my angular project the imports are always as @GeorgeKnap mentioned import { } from 'app/...' but in a nodejs project (which has pretty much the same configuration as the angular project) the auto imports in vs code are ALWAYS relative
also I don't see any of the tslint issues in the nodejs project while tslint extension works fine for the angular project. I tried to configure both things the same way, but some thing is screwed up and it leads to relative imports???- weird
We now have logic to prefer local imports where possible (but global imports for e.g. node modules), so I think the original issue can be considered fixed.
And in the case that there's a baseUrl, we do provide both options. See #19920.
Most helpful comment
I see your point. Probably there will be 2 groups of people on this discussion. So why not make it configurable? In my case, I'm working with VS Code and then it would be nice to just have a setting
typescript.relativeImportwhich could be set totrueorfalse.