eslint-plugin-types
A type checking plugin for eslint.
Installation
You'll first need to install ESLint:
$ npm i eslint --save-dev
Next, install eslint-plugin-types
:
$ npm install eslint-plugin-types --save-dev
Note: If you installed ESLint globally (using the -g
flag) then you must also install eslint-plugin-types
globally.
Usage
Add types
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
Then configure the rules you want to use under the rules section.
Supported Rules
assign-type
Variables must not change type once declared.
Correct:
let a = 'one';a = 'two'; { let a = 1; a = 2;} { a = 'three';}
Incorrect:
let a = '1';a = 2; // error
array-type
Arrays items must be a consistent type.
Correct:
let a = 1 2;a;a2 = 4;
Incorrect:
let a = 1 2 '3'; // errora; // errora3 = '5'; // error let b = ;b;b; // error