Home > Net >  RTK Query - eslint gives errors @typescript-eslint/no-invalid-void-type if query's parameter is
RTK Query - eslint gives errors @typescript-eslint/no-invalid-void-type if query's parameter is

Time:12-06

I have a query function without parameter.

  endpoints: (build) => ({
    fetchEvents: build.query<Test[], void>({
      query: () => '/test'
    }),
  })

ES-Lint errors:

void is only valid as a return type or generic type argument
@typescript-eslint/no-invalid-void-type

What should be used instead of void?

Update

This is my .eslintrc.js

module.exports = {
    "env": {
        "browser": true,
        "es2021": true
    },
    "extends": [
        "plugin:react/recommended",
        "standard-with-typescript",
        'eslint:recommended',
        "prettier"
    ],
    "overrides": [

    ],
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "ecmaVersion": "latest",
        "sourceType": "module",
        "project": "./tsconfig.json",
    },
    "plugins": [
        "react",
        "@typescript-eslint",
        "prettier"
    ],
    "rules": {
        "@typescript-eslint/consistent-type-definitions": ["error", "type"],
        
    },
    settings: {
        "react": {
            "version": "detect",
        },
    }
}

CodePudding user response:

This is a warning (or error) because someone in your project decided it should be an error - it has no technical reason and can be changed in your eslint configuration at any time.

Redux Toolkit uses the void type here - it is the correct way of doing this.

  • Related