Currently, I am working on a project where I have incorporated Typescript and ESLint. However, I have encountered an issue with the error message stating:
An object literal cannot have multiple properties with the same name.
I am looking to disable this specific checking for this error in the line, but I am unsure of how to go about it.
This seems related to the no-dupe-keys
rule mentioned in the documentation, yet it does not seem to function properly within my project context.
testFetch.ts
import fetch from 'node-fetch';
export function testRequest() {
const url:string = 'https://example.com/api';
// eslint-disable-next-line camelcase
const test_camel = 'sd'
const body = {
"key[0]": "arr_val_1",
// eslint-disable-next-line no-dupe-keys
"key[0]": "arr_val_2",
// eslint-disable-next-line camelcase
"key[1]": test_camel,
}
fetch(url, {body})
.then((res) => res.json())
.then((res) => console.log(res))
.catch((err) => console.error('error:' + err));
}
I understand that such unconventional body parameters are necessary here.
Despite this, as depicted in the screenshot, the linter still highlights the issue.
https://i.stack.imgur.com/0B4Zr.png
.eslitrc.cjs
/* eslint-env node */
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
rules: {
"no-dupe-keys": "error",
camelcase: "error",
},
ignorePatterns: [
"test/*",
"dist/*",
".eslintrc.cjs"
],
// "noInlineConfig": true,
};
While the code functions perfectly fine in the playground, it fails to do so in the actual project: