eslint-plugin-jsonc icon indicating copy to clipboard operation
eslint-plugin-jsonc copied to clipboard

Plugin gets a type error when loading it with `defineConfig`

Open Zamiell opened this issue 4 months ago • 0 comments

In 2025, the idiomatic way to create your ESLint config is by using defineConfig. Thus, using it with this plugin would look something like this:

// @ts-check

import { defineConfig } from "eslint/config";
import jsoncParser from "jsonc-eslint-parser";

export default defineConfig(
  {
    plugins: {
      jsonc: ESLintPluginJSONC,
    },
    languageOptions: {
      parser: jsoncParser,
    },
    files: ["**/.json", "**/.jsonc".],
    rules: {
      "jsonc/auto": "off",
    },
  },
);

However, doing this gives a type error:

Type '{ meta: typeof import("eslint-plugin-jsonc/meta"); configs: { base: { plugins: string[]; overrides: { files: string[]; parser: string; rules: { strict: string; "no-unused-expressions": string; "no-unused-vars": string; }; }[]; }; ... 11 more ...; "flat/all": ({ ...; } | ... 1 more ... | { ...; })[]; }; ... 4 more .....' is not assignable to type 'Plugin'.
  Types of property 'configs' are incompatible.
    Type '{ base: { plugins: string[]; overrides: { files: string[]; parser: string; rules: { strict: string; "no-unused-expressions": string; "no-unused-vars": string; }; }[]; }; "auto-config": { extends: string[]; rules: { "jsonc/auto": string; }; }; ... 10 more ...; "flat/all": ({ ...; } | ... 1 more ... | { ...; })[]; }' is not assignable to type 'Record<string, ConfigObject<RulesConfig> | LegacyConfigObject<RulesConfig, RulesConfig> | ConfigObject<RulesConfig>[]>'.
      Property 'base' is incompatible with index signature.
        Type '{ plugins: string[]; overrides: { files: string[]; parser: string; rules: { strict: string; "no-unused-expressions": string; "no-unused-vars": string; }; }[]; }' is not assignable to type 'ConfigObject<RulesConfig> | LegacyConfigObject<RulesConfig, RulesConfig> | ConfigObject<RulesConfig>[]'.
          Type '{ plugins: string[]; overrides: { files: string[]; parser: string; rules: { strict: string; "no-unused-expressions": string; "no-unused-vars": string; }; }[]; }' is not assignable to type 'LegacyConfigObject<RulesConfig, RulesConfig>'.
            Types of property 'overrides' are incompatible.
              Type '{ files: string[]; parser: string; rules: { strict: string; "no-unused-expressions": string; "no-unused-vars": string; }; }[]' is not assignable to type 'ConfigOverride<RulesConfig>[]'.
                Type '{ files: string[]; parser: string; rules: { strict: string; "no-unused-expressions": string; "no-unused-vars": string; }; }' is not assignable to type 'ConfigOverride<RulesConfig>'.
                  Types of property 'rules' are incompatible.
                    Type '{ strict: string; "no-unused-expressions": string; "no-unused-vars": string; }' is not assignable to type 'Partial<RulesConfig>'.
                      Property 'strict' is incompatible with index signature.
                        Type 'string' is not assignable to type 'RuleConfig<unknown[]>'.

I suspect this is related to having the wrong types in the createRule function here: https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/lib/utils/index.ts#L18C4-L18C14

For now, I'll suppress the error using "// @ts-expect-error", but it would be great if this could work properly out of the box in the future.

In closing, thanks for the excellent plugin.

Zamiell avatar Nov 28 '25 20:11 Zamiell