0

我正在使用 craco 和 typescript 设置应用程序。从我将 TS、eslint 和 prettier 添加到我的项目的那一刻起,我无法编译它,因为我不断收到错误:

期望一个赋值或函数调用,而是看到一个表达式 @typescript-eslint/no-unused-expressions

此错误所指的行如下:

async createOrUpdateModalOpen(entityDto: EntityDto): Promise<void> {
    if (entityDto.id === 0) {
        this.props.tenantStore.createTenant();
    } else {
        await this.props.tenantStore.get(entityDto);
    }

    this.setState({ tenantId: entityDto.id });
    this.Modal();

    setTimeout(() => {
        if (entityDto.id !== 0) {
            this.formRef.current?.setFieldsValue({
                ...this.props.tenantStore.tenantModel,
            });
        } else {
            this.formRef.current?.resetFields();
        }
    }, 100);
}

特别是:this.formRef.current?.setFieldsValue({

以下是我的 .eslintrc.js、.prettierrc 和 tsconfig.json 文件供参考:

.eslintrc.js

module.exports = {
    parser: '@typescript-eslint/parser',
    extends: [
        'plugin:react/recommended',
        'plugin:@typescript-eslint/recommended',
        'plugin:prettier/recommended',
    ],
    parserOptions: {
        ecmaVersion: 2018,
        sourceType: 'module',
        ecmaFeatures: {
            jsx: true,
        },
    },
    rules: {
        "prettier/prettier": [
            "error",
            {
              "endOfLine": "auto"
            }
        ],
        "@typescript-eslint/no-this-alias": "off",
        "@typescript-eslint/no-unused-expressions": "off"
    },
    settings: {
        react: {
            version: 'detect',
        },
    },
};

.prettierrc

{
  "singleQuote": true,
  "trailingComma": "all",
  "printWidth": 120,
  "tabWidth": 4,
  "semi": true,
  "endOfLine": "crlf",
  "overrides": [
    {
      "files": ".prettierrc",
      "options": {
        "parser": "json"
      }
    }
  ]
}

tsconfig.json

{
  "compilerOptions": {
    "module": "esnext",
    "target": "es5",
    "sourceMap": true,
    "jsx": "preserve",
    "moduleResolution": "node",
    "rootDir": "src",
    "forceConsistentCasingInFileNames": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "importHelpers": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": false,
    "resolveJsonModule": true,
    "noEmit": true,
    "allowJs": true,
    "isolatedModules": true,
    "downlevelIteration": true,
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "declaration": true,
    "noUnusedParameters": true,
    "incremental": true,
    "noFallthroughCasesInSwitch": true,
  },
  "exclude": ["node_modules", "build", "scripts", "acceptance-tests", "webpack", "jest", "src/setupTests.ts"],
  "include": ["src"]
}
4

0 回答 0