How to Prevent Import of Some Modules with TSLint

Ariel Henryson
1 min readJan 8, 2020

--

When working on a TypeScript project in a modern IDE like WebStorm or VSCode it trys to autocomplete and automatically add ‘imports’ to your project (based on the dependencies in your package.json) when you type.

The problem with that is that you can accidentally import to your production code a Module that you don’t want, for example, ‘protractor’ when you are working on an Angular project.

Another problem Is that if you want to wrap some library and allow it to import only in a specific file in the application. How can you do this with TSLint ?

You can try to use the ‘import-blacklist’ rule, but the problem is that it is global, so the rule will affect all of your source code.

In order to achieve that I create an extend rule that lets you set a blacklist but with ignore list for each Module.

Check out this link
https://www.npmjs.com/package/tslint-import-blacklist-with-ignore-files

--

--