ota-meshi / eslint-plugin-jsonc

ESLint plugin for JSON(C|5)? files
https://ota-meshi.github.io/eslint-plugin-jsonc/
MIT License
181 stars 17 forks source link

Align types with ESLint #309

Closed alecmev closed 3 months ago

alecmev commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

After switching to typescript-eslint's types, as per https://github.com/typescript-eslint/typescript-eslint/issues/8613#issuecomment-1983584487, the error around plugin goes away, but not rules.

ota-meshi commented 3 months ago

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.

JounQin commented 3 months ago

Doesn't https://github.com/DefinitelyTyped/DefinitelyTyped/pull/68232 help?

alecmev commented 3 months ago

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 commented 3 months ago

as const would help then.

Logicer16 commented 3 months ago

This should be fixed in #322