Skip to content

configs field is wrongly optional in the type definition #392

@rhysd

Description

@rhysd

Repro

Run tsc on this eslint.config.mjs.

import ts from 'typescript-eslint';
import mocha from 'eslint-plugin-mocha';

export default ts.config(
    mocha.configs['recommended'],
);

Expected behavior

Type check should pass.

Actual behavior

Got the following errors.

eslint.config.mjs:10:5 - error TS18048: 'mocha.configs' is possibly 'undefined'.

10     mocha.configs['recommended'],
       ~~~~~~~~~~~~~

eslint.config.mjs:10:5 - error TS2345: Argument of type 'LegacyConfig<RulesRecord, RulesRecord> | Config<RulesRecord> | Config<RulesRecord>[]' is not assignable to parameter of type 'InfiniteDepthConfigWithExtends'.
  Type 'LegacyConfig<RulesRecord, RulesRecord>' is not assignable to type 'InfiniteDepthConfigWithExtends'.
    Type 'LegacyConfig<RulesRecord, RulesRecord>' is not assignable to type 'ConfigWithExtends'.
      Types of property 'extends' are incompatible.
        Type 'string | string[] | undefined' is not assignable to type 'InfiniteDepthConfigWithExtends[] | undefined'.
          Type 'string' is not assignable to type 'InfiniteDepthConfigWithExtends[]'.

10     mocha.configs['recommended'],
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 2 errors in the same file, starting at: eslint.config.mjs:10

Description

These errors were caused because the mocha instance is typed as ESLint.Plugin.

const mochaPlugin: ESLint.Plugin = {

ESLint.Plugin is a generic eslint plugin object which knows nothing about eslint-plugin-mocha. So it types configs field as optional. However eslint-plugin-mocha actually sets the configs field and the field should not be optional.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions