Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript issue in flat config: Types of property 'parser' are incompatible #203

Open
silverwind opened this issue Dec 11, 2024 · 5 comments
Labels
help wanted Extra attention is needed PR welcome

Comments

@silverwind
Copy link

silverwind commented Dec 11, 2024

Given the following flat config (in a shared config):

import importPlugin from "eslint-plugin-import-x";
import type {Linter} from "eslint";

export default [{
  plugins: {
    "import-x": importPlugin,
  },
}] satisfies Array<Linter.Config>;

I'm presented with the following boatload of a typescript error on line 6:

index.ts:6:5 - error TS2322: Type '{ configs: { 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-duplica...' 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, LegacyConfig<RulesRecord, RulesRecord> | Config<RulesRecord> | Config<RulesRecord>[]>'.
      Property ''stage-0'' is incompatible with index signature.
        Type 'PluginConfig' is not assignable to type 'LegacyConfig<RulesRecord, RulesRecord> | Config<RulesRecord> | Config<RulesRecord>[]'.
          Type '{ plugins?: ["import-x"] | undefined; settings?: { "import-x/cache"?: { lifetime?: number | "∞" | "Infinity" | undefined; } | undefined; "import-x/core-modules"?: string[] | undefined; ... 9 more ...; "import-x/resolver-next"?: NewResolver[] | undefined; } | undefined; rules?: Record<...> | undefined; } & Config' is not assignable to type 'LegacyConfig<RulesRecord, RulesRecord> | Config<RulesRecord> | Config<RulesRecord>[]'.
            Type '{ plugins?: ["import-x"] | undefined; settings?: { "import-x/cache"?: { lifetime?: number | "∞" | "Infinity" | undefined; } | undefined; "import-x/core-modules"?: string[] | undefined; ... 9 more ...; "import-x/resolver-next"?: NewResolver[] | undefined; } | undefined; rules?: Record<...> | undefined; } & Config' 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'.

Not sure how long this error is there, I'm still using eslintrc config, but am trying to finally migrate to flat.

@SukkaW
Copy link
Collaborator

SukkaW commented Dec 12, 2024

@silverwind I can look into improving a few types of config presets.

@silverwind
Copy link
Author

silverwind commented Dec 12, 2024

Thanks. The error probably went unnoticed so far because eslint configs are usually JS, not TS.

@SukkaW
Copy link
Collaborator

SukkaW commented Dec 14, 2024

@silverwind So I have been looking into this. We have typed our rules with satisfies Record<string, TSESLint.RuleModule<string, readonly unknown[]>> (which is from typescript-eslint) which is conflicted with @types/eslint.

So I don't know what to do. if we make eslint-plugin-import-x compliant with @types/eslint, we will lose type information about the rule config. But if we stick with typescript-eslint, we can't use eslint-plugin-import-x with @types/eslint's types.

@SukkaW SukkaW added help wanted Extra attention is needed PR welcome labels Dec 14, 2024
@silverwind
Copy link
Author

Hmm, sounds like a bug in either typescript-eslint or @types/eslint, tbh.

@SukkaW
Copy link
Collaborator

SukkaW commented Dec 15, 2024

Hmm, sounds like a bug in either typescript-eslint or @types/eslint, tbh.

Nah. It just happens that they both maintain their own types and are not compatible with each other. We use the types from typescript-eslint because we also use utilities from them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed PR welcome
Projects
None yet
Development

No branches or pull requests

2 participants