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

Align types with ESLint #309

Closed
alecmev opened this issue Mar 7, 2024 · 8 comments
Closed

Align types with ESLint #309

alecmev opened this issue Mar 7, 2024 · 8 comments

Comments

@alecmev
Copy link

alecmev commented Mar 7, 2024

I'm getting the following errors with skipLibCheck: false:

... - error TS2322: 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; }; }[]; }; ... 5 more ...; all: { ...; }; }; ... 4 more ...; getStaticJSONValue: { ...; }; }' 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; }; }; ... 4 more ...; all: { ...; }; }' is not assignable to type 'Record<string, FlatConfig | FlatConfig[] | ConfigData<RulesRecord>>'.
      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 'FlatConfig | FlatConfig[] | ConfigData<RulesRecord>'.
          Type '{ plugins: string[]; overrides: { files: string[]; parser: string; rules: { strict: string; "no-unused-expressions": string; "no-unused-vars": string; }; }[]; }' is not assignable to type 'ConfigData<RulesRecord>'.
            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<RulesRecord>[]'.
                Type '{ files: string[]; parser: string; rules: { strict: string; "no-unused-expressions": string; "no-unused-vars": string; }; }' is not assignable to type 'ConfigOverride<RulesRecord>'.
                  Types of property 'rules' are incompatible.
                    Type '{ strict: string; "no-unused-expressions": string; "no-unused-vars": string; }' is not assignable to type 'Partial<RulesRecord>'.
                      Property 'strict' is incompatible with index signature.
                        Type 'string' is not assignable to type 'RuleEntry<any[]> | undefined'.

12     plugins: { jsonc: plugin },
                  ~~~~~

... - error TS2322: Type '{ "jsonc/comma-dangle": string; "jsonc/no-bigint-literals": string; "jsonc/no-binary-expression": string; "jsonc/no-binary-numeric-literals": string; "jsonc/no-comments": string; "jsonc/no-dupe-keys": string; ... 22 more ...; "jsonc/vue-custom-block/no-parsing-error": string; }' is not assignable to type 'RulesRecord'.
  Property '"jsonc/comma-dangle"' is incompatible with index signature.
    Type 'string' is not assignable to type 'RuleEntry<any[]>'.

18     rules: plugin.configs['recommended-with-json'].rules,
       ~~~~~

  node_modules/@types/eslint/index.d.ts:1307:9
    1307         rules?: RulesRecord;
                 ~~~~~
    The expected type comes from property 'rules' which is declared here on type 'FlatConfig'

I'm using a flat config, but I don't think that's the reason.

@ota-meshi ota-meshi added the needs repro Need a repository that can reproduce the problem label Mar 7, 2024
@ota-meshi
Copy link
Owner

I don't really understand what you mean by problem. The types provided by this plugin are of no use to anyone other than the person writing the plugin.
Are you asking to remove d.ts from this plugin? If not, please provide a repository that reproduces the problem.

@alecmev
Copy link
Author

alecmev commented Mar 7, 2024

Are you asking to remove d.ts from this plugin?

No, the presence of .d.ts is appreciated.

The types provided by this plugin are of no use to anyone other than the person writing the plugin.

Hmm, I'm just a user, and they're useful to me. My eslint.config.js is type-checked, because I like being told by TypeScript when I don't put something in the right spot, which happens relatively often.

If not, please provide a repository that reproduces the problem.

Sure! Here: https://github.com/alecmev/eslint-plugin-jsonc-repro-309 Run npm i and then npx tsc.

@alecmev
Copy link
Author

alecmev commented Mar 7, 2024

After switching to typescript-eslint's types, as per typescript-eslint/typescript-eslint#8613 (comment), the error around plugin goes away, but not rules.

@ota-meshi
Copy link
Owner

I checked, and I think it's a bug in @types/eslint. The @types/eslint type definition cannot accept nodes other than @types/estree, but eslint can accept extended nodes.

@ota-meshi ota-meshi added upstream issue and removed needs repro Need a repository that can reproduce the problem labels Mar 8, 2024
@JounQin
Copy link
Collaborator

JounQin commented Mar 8, 2024

Doesn't DefinitelyTyped/DefinitelyTyped#68232 help?

@alecmev
Copy link
Author

alecmev commented Mar 16, 2024

I think the problem is that string just isn't specific enough. It should be "error" | "warn" | "off", or even just the exact value, which is "error" in this case.

@JounQin
Copy link
Collaborator

JounQin commented Mar 16, 2024

as const would help then.

@Logicer16
Copy link
Contributor

This should be fixed in #322

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

No branches or pull requests

4 participants