Skip to content

Unable to use defineConfig() with TypeScript config #421

@thernstig

Description

@thernstig

The following:

import js from '@eslint/js';
import { defineConfig } from 'eslint/config';
import { importX } from 'eslint-plugin-import-x';
import tseslint from 'typescript-eslint';

export default defineConfig([
  js.configs.recommended,
  tseslint.configs.strictTypeChecked,
  tseslint.configs.stylisticTypeChecked,
  {
    // Required for strictTypeChecked
    languageOptions: {
      parserOptions: {
        projectService: true,
        tsconfigRootDir: import.meta.dirname,
      },
    },
  },
  {
    plugins: {
      'import-x': importX,
    },
    extends: ['import-x/flat/recommended'],
  },
]);

Gives this error when hover 'import-x':

Type '{ meta: { name: string; version: string; }; rules: { 'no-unresolved': RuleModule<MessageId$12, [(Options$26 | undefined)?], ImportXPluginDocs, RuleListener>; ... 45 more ...; 'imports-first': RuleModule<...>; }; cjsRequire: CjsRequire; importXResolverCompat: (resolver: LegacyResolver | NewResolver, resolverOptions?:...' is not assignable to type 'Plugin'.
  Types of property 'configs' are incompatible.
    Type '{ recommended: { plugins: ["import-x"]; rules: { 'import-x/no-unresolved': "error"; 'import-x/named': "error"; 'import-x/namespace': "error"; 'import-x/default': "error"; 'import-x/export': "error"; 'import-x/no-named-as-default': "warn"; 'import-x/no-named-as-default-member': "warn"; 'import-x/no-duplicates': "warn...' is not assignable to type 'Record<string, Config<RulesRecord> | LegacyConfig<RulesRecord, RulesRecord> | Config<RulesRecord>[]>'.
      Property ''stage-0'' is incompatible with index signature.
        Type 'PluginConfig' is not assignable to type 'Config<RulesRecord> | LegacyConfig<RulesRecord, RulesRecord> | Config<RulesRecord>[]'.
          Type 'PluginConfig' is not assignable to type 'LegacyConfig<RulesRecord, RulesRecord>'.
            Types of property 'overrides' are incompatible.
              Type 'ConfigOverride[] | undefined' is not assignable to type 'ConfigOverride<RulesRecord>[] | undefined'.
                Type 'ConfigOverride[]' is not assignable to type 'ConfigOverride<RulesRecord>[]'.
                  Type 'ConfigOverride' is not assignable to type 'ConfigOverride<RulesRecord>'.
                    Types of property 'parser' are incompatible.
                      Type 'string | null | undefined' is not assignable to type 'string | undefined'.
                        Type 'null' is not assignable to type 'string | undefined'.

Would the solution be to update the parser property in stage-0 config to use undefined instead of null?

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