Verifies whether you should be using the `import from` or `import require` syntax when importing an external module to follow the ES6 spec
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
rules
.gitignore
.npmignore
LICENSE
README.md
circle.yml
index.js
package.json
tsconfig.json
tslint.json
yarn.lock

README.md

tslint-proper-import-require

A TSLint rule that verifies whether you should be using the import from or import require syntax when importing an external module to follow the ES6 spec, without depending on workarounds supplied by Typescript that have the potential to be removed in the future.

The rule works by resolving your specified module and checking if __esModule exists in the modules main exported file, and then reports accordingly.

Usage

In your tslint.json set the following:

{
  "extends": ["tslint-proper-import-require"],
  "rules": {
    "proper-import-require": true
  }
}

Examples

Importing an < ES6 module

example-module/index.js

module.exports = function() {
  return 'foo':
}

index.ts

import * as ExampleModule from 'example-module'; // Incorrect
import ExampleModule = require('example-module'); // Correct

Importing an ES6 module

example-module/index.js

export function foo() {
  return 'bar';
}

index.ts

import * as ExampleModule from 'example-module'; // Correct
import { foo } from 'example-module'; // Correct
import ExampleModule = require('example-module'); // Incorrect