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

Config types don't satisfy FlatConfig.Config #2442

Open
4 tasks
alecmev opened this issue Jul 25, 2024 · 0 comments
Open
4 tasks

Config types don't satisfy FlatConfig.Config #2442

alecmev opened this issue Jul 25, 2024 · 0 comments

Comments

@alecmev
Copy link

alecmev commented Jul 25, 2024

Issue workflow progress

Progress of the issue based on the Contributor Workflow

  • 1. The issue provides a reproduction available on GitHub, Stackblitz or CodeSandbox
  • 2. A failing test has been provided
  • 3. A local solution has been provided
  • 4. A pull request is pending review

Describe the bug

Our ESLint configuration is written in TypeScript. The following:

import * as plugin from '@graphql-eslint/eslint-plugin';
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint';

export const CONFIG: FlatConfig.Config[] = [
  {
    ...plugin.flatConfigs['schema-recommended'],
    files: ['**/schema.graphql'],
  },
];

Is reported as erroneous by TypeScript:

Type '{ files: string[]; languageOptions: { parser: { parseForESLint: typeof plugin.parseForESLint; }; }; rules: { "@graphql-eslint/description-style": string; "@graphql-eslint/known-argument-names": string; "@graphql-eslint/known-directives": string; "@graphql-eslint/known-type-names": string; "@graphql-eslint/lone-schem...' is not assignable to type 'Config'.
  Types of property 'rules' are incompatible.
    Type '{ '@graphql-eslint/description-style': string; '@graphql-eslint/known-argument-names': string; '@graphql-eslint/known-directives': string; '@graphql-eslint/known-type-names': string; ... 15 more ...; '@graphql-eslint/unique-type-names': string; }' is not assignable to type 'Partial<Record<string, RuleEntry>>'.
      Property ''@graphql-eslint/description-style'' is incompatible with index signature.
        Type 'string' is not assignable to type 'RuleEntry | undefined'.

FlatConfig.Config is a loose version of ESLint's own Linter.FlatConfig, just in case.

To reproduce

Use this plugin in a type-checked configuration, as above.

Expected behavior

No errors.

Environment:

  • @graphql-eslint/eslint-plugin: 4.0.0-alpha.0

Additional context

Workaround:

import * as plugin from '@graphql-eslint/eslint-plugin';
import type { FlatConfig } from '@typescript-eslint/utils/ts-eslint';

export const CONFIG: FlatConfig.Config[] = [
  {
    ...(plugin.flatConfigs[
      'schema-recommended'
    ] as unknown as FlatConfig.Config),
    files: ['**/schema.graphql'],
  },
];

The cause is likely the fact that the rules aren't exported with as const (preserving specific string literals and tuples). And satisfies could be more specific here, utilizing Linter.FlatConfig instead of unknown, for example:

} satisfies Record<ConfigName, unknown>;

Let me know if you need more details or a reproduction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant