0.0.6 • Published 8 years ago
tslint-proper-import-require v0.0.6
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'); // CorrectImporting 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