Eslint unable to parse this typescript code.
export const swapKeyAndValue = <T extends { [index: string]: string }>(
obj: T
) => {
const newObj: { [prop: string]: string } = {}
for (const prop in obj) {
newObj[obj[prop]] = prop
}
return newObj as { [K in keyof T as T[K]]: K }
}
I cannot disable Eslint on this line, I have to exclude this file in Eslint config.
The code itself however works as expected.
Eslint config
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:import/errors',
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
parser: '@typescript-eslint/parser',
ignorePatterns: [
'dist/**/*', // Ignore built files.
],
plugins: ['@typescript-eslint', 'import'],
rules: {
'import/no-unresolved': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'error',
camelcase: 'off',
},
}
typescript: 3.9.7 eslint: 7.32.0
