Force configured functions to include explicit generics
npm install eslint-plugin-require-explicit-genericsany type.
myFunction in your .eslintrc.js:
ts
myFunction(); // ❌ ESLint: Function 'myFunction' must be called with explicit generics...
myFunction(); // ✅ ESLint: Pass
`
Installation
First install ESLint:
`shell
npm
npm install eslint --save-dev
yarn
yarn add eslint --dev
`
Next, install eslint-plugin-require-explicit-generics
`shell
npm
npm install eslint-plugin-require-explicit-generics --save-dev
yarn
yarn add eslint-plugin-require-explicit-generics --dev
`
Configuration (REQUIRED)
In your .estlintrc.js add "require-explicit-generics" to the plugin list.
`js
plugins: [
"require-explicit-generics",
],
`
Then in the rules section set "require-explicit-generics/require-explicit-generics"
pass the log level (either "error" or "warning"),
then the list of functions to check.
`js
rules: {
"require-explicit-generics/require-explicit-generics": [
"error",
// List your functions here
[ "myFunction", "myVar.myOtherFunction" ]
]
},
`
You can also use a map to define how many generics to expect for each function.
`js
rules: {
"require-explicit-generics/require-explicit-generics": [
"error",
{ "myFunction": 3, "myVar.myOtherFunction": 1 }
]
},
`
`ts
myVar.myOtherFunction(); // Function 'myVar.myOtherFunction' must be called with generics...
myFunction(); // Function 'myOtherFunction' called with too few explicit generics...
``