Skip to content

Type Error: env property in plugin configs is not assignable to Config<RulesRecord> in TypeScriptΒ #737

@antoinezanardi

Description

@antoinezanardi

Description:

When using @vitest/eslint-plugin in a flat ESLint config with TypeScript, I encounter the following type error:

TS2322: Type '{ meta: { name: string; version: string; }; rules: { ... } }' is not assignable to type 'Plugin'.
  Types of property 'configs' are incompatible.
    Type '{ ...; env: { ... } }' is not assignable to type 'Record<string, Config<RulesRecord> | LegacyConfig<RulesRecord, RulesRecord> | Config<RulesRecord>[]>'.
      Property 'env' is incompatible with index signature.
        Type '{ name: string; languageOptions: { globals: { ... } } }' is not assignable to type 'Config<RulesRecord> | LegacyConfig<RulesRecord, RulesRecord> | Config<RulesRecord>[]'.
          Type '{ name: string; languageOptions: { globals: { ... } } }' is not assignable to type 'Config<RulesRecord>'.
            The types of 'languageOptions.globals' are incompatible between these types.
              Type '{ suite: string; ... }' is not assignable to type 'Globals'.
                Property 'suite' is incompatible with index signature.
                  Type 'string' is not assignable to type 'GlobalConf'.

Excerpt from my config:

import Vitest from "@vitest/eslint-plugin";
import type { Linter } from "eslint";

const ESLINT_TESTS_CONFIG = {
  name: "tests",
  files: ["tests/**/*.spec.ts"],
  plugins: { vitest: Vitest },
  // ...
} satisfies Linter.Config;

Environment:

  • @vitest/eslint-plugin version: 1.3.4
  • TypeScript version: 5.8.3
  • ESLint version: 9.30.1

Steps to reproduce:

  1. Import and use the plugin in a flat ESLint config with TypeScript.
  2. Assign the plugin to the plugins property.
  3. Type-check the config.

Expected behavior:
No type errors should occur when using the plugin in a flat config with TypeScript.

Actual behavior:
TypeScript reports a type incompatibility for the env property in the plugin's configs.

Additional context:
It appears the env config in the plugin uses a globals object with string values, but the expected type is GlobalConf. This causes a type mismatch in strict TypeScript projects.


Thank you for your work on this plugin! πŸ’š

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions