
Fix typescript error: Unexpected any and empty object issues

2 min read•7 views
To fix the typescript error: Unexpected any and empty object issues
eslint.config.mjs
import { dirname } from "path";
import { fileURLToPath } from "url";
import { FlatCompat } from "@eslint/eslintrc";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
});
const eslintConfig = [
...compat.extends("next/core-web-vitals", "next/typescript"),
// = = = = = = = = = = = = = = = = = =
// TO AVOID ERROR OF
// Unexpected any. Specify a different type.eslint@typescript-eslint/no-explicit-any
// AND
// The {} ("empty object") type allows any non-nullish value, including literals like 0 and "".
// = = = = = = = = = = = = = = = = = =
{
rules: {
// Turn off `no-explicit-any`
"@typescript-eslint/no-explicit-any": "off",
// Allow `{}` as a valid type
"@typescript-eslint/ban-types": [
"error",
{
"types": {
"{}": false,
},
},
],
},
parserOptions: {
project: "./tsconfig.json",
tsconfigRootDir: __dirname,
},
},
// = = = = = = = = = = = = = = = = = =
// ERROR FIXED
// = = = = = = = = = = = = = = = = = =
];
export default eslintConfig;