Is it possible to disable the typedef rule only for array or object destructuring in lambdas?
getPersonsNames(): string[] {
type Person = { name: string; age: number };
const persons: Person[] = [
{ name: `Jan Kowalski`, age: 12 },
{ name: `Justyna Kowalczyk`, age: 22 }
];
return persons.map(({ name }) => name);
}
I prefer to use typedefs for destructuring, but I want to exclude these specific cases. Is there a way to do this?
I attempted to add 'arrow-parameter': false,
(and arrowParameter: false
as shown above) to @typescript-eslint/typedef
, but it had no effect.
Documentation of the rule used: @typescript-eslint/typedef
Files for Reproduction
.eslintrc.js
configuration file:
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: './tsconfig.json',
createDefaultProgram: true,
ecmaVersion: 2020,
sourceType: 'module',
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
'@typescript-eslint/typedef': [
'error',
{
'arrowParameter': false,
'propertyDeclaration': true,
'parameter': true,
'memberVariableDeclaration': true,
'callSignature': true,
'variableDeclaration': true,
'arrayDestructuring': true,
'objectDestructuring': true
}
],
},
}
.gitignore
:
node_modules
index.ts
:
function getPersonsNames(): string[] {
type Person = { name: string; age: number };
const persons: Person[] = [
{ name: `Jan Kowalski`, age: 12 },
{ name: `Justyna Kowalczyk`, age: 22 }
];
return persons.map(({ name }) => name);
}
getPersonsNames();
package.json
:
{
"name": "typedef-in-destructuring-lambdas",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint . --ext .ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.3.0",
"@typescript-eslint/parser": "^4.3.0",
"eslint": "^7.10.0",
"typescript": "^4.0.3"
}
}
tsconfig.json
:
{
"compilerOptions": {
"target": "ES2017",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"noEmit": true,
"noEmitHelpers": true,
"importHelpers": true,
"strictNullChecks": false,
"skipLibCheck": true,
"lib": [
"dom",
"es6",
"es2019"
]
}
}