Skip to content

Conversation

@JasonWeinzierl
Copy link

@JasonWeinzierl JasonWeinzierl commented Feb 4, 2025

This fixes compatibility with the TSESLint.FlatConfig.Rules interface from @typescript-eslint/utils.

Resolves #377

Description

When using TypeScript to write an ESLint flat config, the following will cause a compile error:

// @ts-check
import tseslint from 'typescript-eslint';
import jasmine from 'eslint-plugin-jasmine';

export default tseslint.config({
  plugins: {
    jasmine,
  },
  extends: [
    jasmine.configs.recommended,
  ],
});
Type '{ rules: { 'jasmine/expect-matcher': number; 'jasmine/expect-single-argument': number; 'jasmine/named-spy': number; 'jasmine/no-focused-tests': number; 'jasmine/no-disabled-tests': number; 'jasmine/no-describe-variables': number; ... 15 more ...; 'jasmine/prefer-toBeUndefined': number; }; }' is not assignable to type 'Config'.
  Types of property 'rules' are incompatible.
    Type '{ 'jasmine/expect-matcher': number; 'jasmine/expect-single-argument': number; 'jasmine/named-spy': number; 'jasmine/no-focused-tests': number; 'jasmine/no-disabled-tests': number; 'jasmine/no-describe-variables': number; ... 15 more ...; 'jasmine/prefer-toBeUndefined': number; }' is not assignable to type 'Partial<Record<string, RuleEntry>>'.
      Property ''jasmine/expect-matcher'' is incompatible with index signature.
        Type 'number' is not assignable to type 'RuleEntry | undefined'.ts(2322)

This PR fixes this error by doing the JSDoc-equivalent of TypeScript's as const, narrowing each value of rules from number to 0|1|2.

How has this been tested?

  1. Edited the index.js in node_modules.
  2. The error goes away and ESLint continues to work.
  3. Ran npm run test

Types of changes

  • Test change (non-breaking change which adds additional test scenarios)
  • Refactor change (non-breaking change updates coding styles)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have ran npm run test and everything passes
  • My code follows the code style of this project
  • I have updated the documentation where necessary
  • I have read the CONTRIBUTING document
  • I have added tests to cover my changes
  • All new and existing tests pass

This fixes compatibility with the `TSESLint.FlatConfig.Rules` interface from `@typescript-eslint/utils`.
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

Successfully merging this pull request may close these issues.

Recommended rules are configured with numbers, but TS-eslint expects strings

1 participant