typescript-eslint: [ban-types] Default options are never removed

Repro

module.exports = {
    parser: '@typescript-eslint/parser',
    plugins: ['@typescript-eslint'],
    rules: {
        '@typescript-eslint/ban-types': [
            'error',
            {
                types: {
                    Omit: 'Prefer `OmitStrict`.',
                },
            },
        ],
    },
};
// Don't use 'Object' as a type. Use Record<string, any> instead
type Foo1 = Object;
// Don't use 'Boolean' as a type. Use boolean instead
type Foo2 = Boolean;
// Don't use 'Number' as a type. Use number instead
type Foo3 = Number;

Expected Result No errors, because I am overriding the default options.

Actual Result Each line errors. It is not possible to disable the default options.

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 1.11.0
@typescript-eslint/parser 1.11.0
TypeScript 3.5.2
ESLint 6.0.1
node 8.15.1
npm 6.9.0

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 15 (10 by maintainers)

Most upvoted comments

No good reason. Just didn’t expect to have them forced on me. They’re only supposed to be defaults after all.

I agree it would be nice to be able to ban only your selected types and get rid of the defaults, but it’s also useful to be able to add some types to be banned and still have the defaults banned (without having to add them again in the rule configuration). So maybe config like this could be supported:

    '@typescript-eslint/ban-types': [
        'error',
        {
            types: {
                Omit: 'Prefer `OmitStrict`.',
            },
            keepDefaults: true, // keep the default settings
        },
    ]

Looks good if the default behavior is separated into another rule that has a more self-described name. For example, no-wrapper-object-types, prefer-primitive-types, or something like. In core, no-restricted-globals-like rules don’t have defaults.