- 
                Notifications
    You must be signed in to change notification settings 
- Fork 200
How should I use no-relative-imports #435
Description
Hello!
I am amazed how productive became my work with vscode, typescript and this config.
Thank you for your great work with it.
I'm new with typescript and tslint, so I'm a bit confused how to use rule 'no-relative-imports'.
Suppose I have small frontend project with Webpack + Vue + ts-loader.
Main core written with typescript, other files with javascript.
In folder 'core' I have two files:
ElData.ts
...
export class AnimationElement {
  ...
}
...
SportData.ts
import * as ElData from './ElData';
...
The thing is, 'no-relative-imports' throws error:
[tslint] Imported module is being loaded from a relative path. Please use an absolute path: import * as ElData from './ElData'; (no-relative-imports)
Hmm, disable rule is not my way to resolve a problem!
- First thing I try is just remove './' from my import like this:
SportData.ts
import * as ElData from 'ElData';
...
[tslint] Module 'ElData' is not listed as dependency in package.json (no-implicit-dependencies)
Well, lets try another way
- Improve tsconfig.json
{
  ...
  "compilerOptions": {
    ...
    "baseUrl": "./src"
  }
}
And then
SportData.ts
import * as ElData from 'core/ElData';
...
[tslint] Module 'core' is not listed as dependency in package.json (no-implicit-dependencies)
[tslint] Submodule import paths from this package are disallowed; import from the root instead (no-submodule-imports)
Arrgh
- Last hope
My webpack config a bit supercharged with aliases
{
  ....
  resolve: {
    alias: {
      '@': resolve('src'),
    }
  },
  ...
}
SportData.ts
import * as ElData from '@/core/ElData';
...
[tslint] Module '@/core' is not listed as dependency in package.json (no-implicit-dependencies)
[tslint] Submodule import paths from this package are disallowed; import from the root instead (no-submodule-imports)
[ts] Cannot find module '@/core/ElData'.
Jesus, all I achieved is just increase of errors.
How should I cook my imports?