(
): string {
const id = thing.$id != null ? `$${thing.$id}` : '';
// If `type` is a base class, we should print out the name of the subclass
- // eslint-disable-next-line @typescript-eslint/ban-types
+ // eslint-disable-next-line @typescript-eslint/no-wrapper-object-types
const constructorName = (Object.getPrototypeOf(thing) as Object)
.constructor.name;
diff --git a/packages/typescript-eslint/src/configs/all.ts b/packages/typescript-eslint/src/configs/all.ts
index f01ac17c8ddb..dc899379b164 100644
--- a/packages/typescript-eslint/src/configs/all.ts
+++ b/packages/typescript-eslint/src/configs/all.ts
@@ -24,7 +24,6 @@ export default (
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
'@typescript-eslint/ban-tslint-comment': 'error',
- '@typescript-eslint/ban-types': 'error',
'@typescript-eslint/class-literal-property-style': 'error',
'class-methods-use-this': 'off',
'@typescript-eslint/class-methods-use-this': 'error',
@@ -94,6 +93,7 @@ export default (
'@typescript-eslint/no-require-imports': 'error',
'no-restricted-imports': 'off',
'@typescript-eslint/no-restricted-imports': 'error',
+ '@typescript-eslint/no-restricted-types': 'error',
'no-shadow': 'off',
'@typescript-eslint/no-shadow': 'error',
'@typescript-eslint/no-this-alias': 'error',
@@ -109,6 +109,7 @@ export default (
'@typescript-eslint/no-unsafe-call': 'error',
'@typescript-eslint/no-unsafe-declaration-merging': 'error',
'@typescript-eslint/no-unsafe-enum-comparison': 'error',
+ '@typescript-eslint/no-unsafe-function-type': 'error',
'@typescript-eslint/no-unsafe-member-access': 'error',
'@typescript-eslint/no-unsafe-return': 'error',
'@typescript-eslint/no-unsafe-unary-minus': 'error',
@@ -121,6 +122,7 @@ export default (
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/no-useless-empty-export': 'error',
+ '@typescript-eslint/no-wrapper-object-types': 'error',
'@typescript-eslint/non-nullable-type-assertion-style': 'error',
'no-throw-literal': 'off',
'@typescript-eslint/only-throw-error': 'error',
diff --git a/packages/typescript-eslint/src/configs/recommended-type-checked.ts b/packages/typescript-eslint/src/configs/recommended-type-checked.ts
index 47b8c9b08ef6..993f7baa90ed 100644
--- a/packages/typescript-eslint/src/configs/recommended-type-checked.ts
+++ b/packages/typescript-eslint/src/configs/recommended-type-checked.ts
@@ -21,7 +21,6 @@ export default (
rules: {
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/ban-ts-comment': 'error',
- '@typescript-eslint/ban-types': 'error',
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/no-array-delete': 'error',
@@ -49,6 +48,7 @@ export default (
'@typescript-eslint/no-unsafe-call': 'error',
'@typescript-eslint/no-unsafe-declaration-merging': 'error',
'@typescript-eslint/no-unsafe-enum-comparison': 'error',
+ '@typescript-eslint/no-unsafe-function-type': 'error',
'@typescript-eslint/no-unsafe-member-access': 'error',
'@typescript-eslint/no-unsafe-return': 'error',
'@typescript-eslint/no-unsafe-unary-minus': 'error',
@@ -56,6 +56,7 @@ export default (
'@typescript-eslint/no-unused-expressions': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
+ '@typescript-eslint/no-wrapper-object-types': 'error',
'no-throw-literal': 'off',
'@typescript-eslint/only-throw-error': 'error',
'@typescript-eslint/prefer-as-const': 'error',
diff --git a/packages/typescript-eslint/src/configs/recommended.ts b/packages/typescript-eslint/src/configs/recommended.ts
index 0c9d5bb3c91e..1e6be3251a08 100644
--- a/packages/typescript-eslint/src/configs/recommended.ts
+++ b/packages/typescript-eslint/src/configs/recommended.ts
@@ -20,7 +20,6 @@ export default (
name: 'typescript-eslint/recommended',
rules: {
'@typescript-eslint/ban-ts-comment': 'error',
- '@typescript-eslint/ban-types': 'error',
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/no-duplicate-enum-values': 'error',
@@ -34,10 +33,12 @@ export default (
'@typescript-eslint/no-this-alias': 'error',
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
'@typescript-eslint/no-unsafe-declaration-merging': 'error',
+ '@typescript-eslint/no-unsafe-function-type': 'error',
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
+ '@typescript-eslint/no-wrapper-object-types': 'error',
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/triple-slash-reference': 'error',
diff --git a/packages/typescript-eslint/src/configs/strict-type-checked.ts b/packages/typescript-eslint/src/configs/strict-type-checked.ts
index 61d0a4d579a2..fb53665756e3 100644
--- a/packages/typescript-eslint/src/configs/strict-type-checked.ts
+++ b/packages/typescript-eslint/src/configs/strict-type-checked.ts
@@ -24,7 +24,6 @@ export default (
'error',
{ minimumDescriptionLength: 10 },
],
- '@typescript-eslint/ban-types': 'error',
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/no-array-delete': 'error',
@@ -64,6 +63,7 @@ export default (
'@typescript-eslint/no-unsafe-call': 'error',
'@typescript-eslint/no-unsafe-declaration-merging': 'error',
'@typescript-eslint/no-unsafe-enum-comparison': 'error',
+ '@typescript-eslint/no-unsafe-function-type': 'error',
'@typescript-eslint/no-unsafe-member-access': 'error',
'@typescript-eslint/no-unsafe-return': 'error',
'@typescript-eslint/no-unsafe-unary-minus': 'error',
@@ -73,6 +73,7 @@ export default (
'@typescript-eslint/no-unused-vars': 'error',
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
+ '@typescript-eslint/no-wrapper-object-types': 'error',
'no-throw-literal': 'off',
'@typescript-eslint/only-throw-error': 'error',
'@typescript-eslint/prefer-as-const': 'error',
diff --git a/packages/typescript-eslint/src/configs/strict.ts b/packages/typescript-eslint/src/configs/strict.ts
index 4a581ff95335..d6c5a37e9c54 100644
--- a/packages/typescript-eslint/src/configs/strict.ts
+++ b/packages/typescript-eslint/src/configs/strict.ts
@@ -23,7 +23,6 @@ export default (
'error',
{ minimumDescriptionLength: 10 },
],
- '@typescript-eslint/ban-types': 'error',
'no-array-constructor': 'off',
'@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/no-duplicate-enum-values': 'error',
@@ -42,12 +41,14 @@ export default (
'@typescript-eslint/no-this-alias': 'error',
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
'@typescript-eslint/no-unsafe-declaration-merging': 'error',
+ '@typescript-eslint/no-unsafe-function-type': 'error',
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'error',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': 'error',
'no-useless-constructor': 'off',
'@typescript-eslint/no-useless-constructor': 'error',
+ '@typescript-eslint/no-wrapper-object-types': 'error',
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/prefer-literal-enum-member': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
diff --git a/packages/utils/src/ts-eslint/Rule.ts b/packages/utils/src/ts-eslint/Rule.ts
index 899b8a98346b..fe3fa0412d07 100644
--- a/packages/utils/src/ts-eslint/Rule.ts
+++ b/packages/utils/src/ts-eslint/Rule.ts
@@ -690,7 +690,7 @@ never only allow unidirectional)
export type LooseRuleCreateFunction = (context: any) => Record<
string,
/*
- eslint-disable-next-line @typescript-eslint/ban-types --
+ eslint-disable-next-line @typescript-eslint/no-unsafe-function-type --
intentionally use Function here to give us the basic "is a function" validation
without enforcing specific argument types so that different AST types can still
be passed to configs
diff --git a/packages/website/blog/2024-05-27-announcing-typescript-eslint-v8-beta.mdx b/packages/website/blog/2024-05-27-announcing-typescript-eslint-v8-beta.mdx
index 6bda8fcbf66e..b30789289077 100644
--- a/packages/website/blog/2024-05-27-announcing-typescript-eslint-v8-beta.mdx
+++ b/packages/website/blog/2024-05-27-announcing-typescript-eslint-v8-beta.mdx
@@ -187,11 +187,45 @@ Several rules are changed in significant enough ways to be considered breaking c
- If you want to have the rule check conditional tests, set its [`ignoreConditionalTests` option](/rules/prefer-nullish-coalescing/#ignoreconditionaltests) to `false` in your ESLint config
- [feat(eslint-plugin): [no-unused-vars] align catch behavior to ESLint 9](https://github.com/typescript-eslint/typescript-eslint/pull/8971)
- If you want [`@typescript-eslint/no-unused-vars`](/rules/no-unused-vars) to ignore caught errors, enable its `caughtErrors` option to `'none'` in your ESLint config
+
+#### Replacement of `ban-types`
+
+[`@typescript-eslint/ban-types`](https://typescript-eslint.io/rules/ban-types) has long been one of the more controversial rules in typescript-eslint.
+It served two purposes:
+
+- Allowing users to ban a configurable list of types from being used in type annotations
+- Banning confusing or dangerous built-in types such as `Function` and `Number`
+
+Notably, `ban-types` banned the built-in `{}` ("empty object") type in TypeScript.
+The `{}` type is a common source of confusion for TypeScript developers because it matches _any non-nullable_ value, including primitives like `""`.
+
+Banning `{}` in `ban-types` was helpful to prevent developers from accidentally using it instead of a more safe type such as `object`.
+On the other hand, there are legitimate uses for `{}`, and banning it by default was harmful in those cases.
+
+typescript-eslint v8 deletes the `ban-types` rule and replaces it with several more targeted rules:
+
+- [`@typescript-eslint/no-restricted-types`](/rules/no-restricted-types) is the new rule for banning a configurable list of type names.
+ It has no options enabled by default.
+- [`@typescript-eslint/no-empty-object-type`](/rules/no-empty-object-type) bans the built-in `{}` type in confusing locations.
+- [`@typescript-eslint/no-unsafe-function-type`](/rules/no-unsafe-function-type) bans the built-in `Function` type
+- [`@typescript-eslint/no-wrapper-object-types`](/rules/no-wrapper-object-types) bans `Object` and built-in class wrappers such as `Number`.
+
+To migrate to the new rules:
+
+- If you were disabling the ban on `{}`, consider enabling [`@typescript-eslint/no-empty-object-type`](https://v8--typescript-eslint.netlify.app/rules/no-empty-object-type), as it allows some cases of `{}` that were previously banned.
+- If you were banning any configurable types lists, provide a similar configuration to [`no-restricted-types`](/rules/no-restricted-types).
+- If you have [`@typescript-eslint/ban-types`](/rules/ban-types) manually enabled, it will no longer ban:
+ - `{}` or `object`: use a [recommended config](/users/configs) or manually enable [`@typescript-eslint/no-empty-object-type`](https://v8--typescript-eslint.netlify.app/rules/no-empty-object-type)
+ - `Function`: use a [recommended config](/users/configs) or manually enable [`@typescript-eslint/no-unsafe-function-type`](https://v8--typescript-eslint.netlify.app/rules/no-unsafe-function-type)
+ - `Number` or other built-in uppercase types: use a [recommended config](/users/configs) or manually enable [`@typescript-eslint/no-wrapper-object-types`](https://v8--typescript-eslint.netlify.app/rules/no-wrapper-object-types)
+- If you have [`@typescript-eslint/no-empty-interface`](/rules/no-empty-interface) manually enabled, remove that, and instead either use a [recommended config](/users/configs) or manually enable [`@typescript-eslint/no-empty-object-type`](https://v8--typescript-eslint.netlify.app/rules/no-empty-object-type)
+
+For more details, see the issues and pull requests that split apart the `ban-types` rule:
+
+- [Enhancement: [ban-types] Split the {} ban into a separate, better-phrased rule](https://github.com/typescript-eslint/typescript-eslint/issues/8700)
- [feat(eslint-plugin): split no-empty-object-type out from ban-types and no-empty-interface](https://github.com/typescript-eslint/typescript-eslint/pull/8977)
- - If you have [`@typescript-eslint/ban-types`](/rules/ban-types) manually enabled, it will no longer ban the `{}` or `object` types; use a [recommended config](/users/configs) or manually enable [`@typescript-eslint/no-empty-object-type`](https://v8--typescript-eslint.netlify.app/rules/no-empty-object-type)
- - If you have [`@typescript-eslint/no-empty-interface`](/rules/no-empty-interface) manually enabled, remove that, and instead either use a [recommended config](/users/configs) or manually enable [`@typescript-eslint/no-empty-object-type`](https://v8--typescript-eslint.netlify.app/rules/no-empty-object-type)
-- ⏳ [Enhancement: [ban-types] Split into default-less no-restricted-types and more targeted type ban rule(s)](https://github.com/typescript-eslint/typescript-eslint/issues/8978)
- - [#9102](https://github.com/typescript-eslint/typescript-eslint/pull/9102) is still in review; we'll update this post when the migration path is settled
+- [Enhancement: [ban-types] Split into default-less no-restricted-types and more targeted type ban rule(s)](https://github.com/typescript-eslint/typescript-eslint/issues/8978)
+- [feat(eslint-plugin): replace ban-types with no-restricted-types, no-unsafe-function-type, no-wrapper-object-types](https://github.com/typescript-eslint/typescript-eslint/pull/9102)
### Tooling Breaking Changes
diff --git a/packages/website/plugins/generated-rule-docs/index.ts b/packages/website/plugins/generated-rule-docs/index.ts
index fd4d8d50efc8..c0a7265d28b4 100644
--- a/packages/website/plugins/generated-rule-docs/index.ts
+++ b/packages/website/plugins/generated-rule-docs/index.ts
@@ -10,7 +10,6 @@ import { insertFormattingNotice } from './insertions/insertFormattingNotice';
import { insertNewRuleReferences } from './insertions/insertNewRuleReferences';
import { insertResources } from './insertions/insertResources';
import { insertRuleDescription } from './insertions/insertRuleDescription';
-import { insertSpecialCaseOptions } from './insertions/insertSpecialCaseOptions';
import { insertWhenNotToUseIt } from './insertions/insertWhenNotToUseIt';
import { removeSourceCodeNotice } from './removeSourceCodeNotice';
@@ -35,7 +34,6 @@ export const generatedRuleDocs: Plugin = () => {
? insertBaseRuleReferences(page)
: await insertNewRuleReferences(page);
- insertSpecialCaseOptions(page);
insertWhenNotToUseIt(page);
insertResources(page);
addESLintHashToCodeBlocksMeta(page, eslintrc);
diff --git a/packages/website/plugins/generated-rule-docs/insertions/insertNewRuleReferences.ts b/packages/website/plugins/generated-rule-docs/insertions/insertNewRuleReferences.ts
index 9d6ccdfa7be2..fcd6196feda8 100644
--- a/packages/website/plugins/generated-rule-docs/insertions/insertNewRuleReferences.ts
+++ b/packages/website/plugins/generated-rule-docs/insertions/insertNewRuleReferences.ts
@@ -20,14 +20,6 @@ const COMPLICATED_RULE_OPTIONS = new Set([
'naming-convention',
]);
-/**
- * Rules that do funky things with their defaults and require special code
- * rather than just JSON.stringify-ing their defaults blob
- */
-const SPECIAL_CASE_DEFAULTS = new Map([
- ['ban-types', '[{ /* See below for default options */ }]'],
-]);
-
const PRETTIER_CONFIG_PATH = path.resolve(
__dirname,
'..',
@@ -190,10 +182,7 @@ function linkToConfigs(configs: string[]): mdast.Node[] {
}
function getRuleDefaultOptions(page: RuleDocsPage): string {
- const defaults =
- SPECIAL_CASE_DEFAULTS.get(page.file.stem) ??
- JSON.stringify(page.rule.defaultOptions);
-
+ const defaults = JSON.stringify(page.rule.defaultOptions);
const recommended = page.rule.meta.docs.recommended;
return typeof recommended === 'object'
diff --git a/packages/website/plugins/generated-rule-docs/insertions/insertSpecialCaseOptions.ts b/packages/website/plugins/generated-rule-docs/insertions/insertSpecialCaseOptions.ts
deleted file mode 100644
index cacce340d634..000000000000
--- a/packages/website/plugins/generated-rule-docs/insertions/insertSpecialCaseOptions.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import * as fs from 'fs';
-import type * as mdast from 'mdast';
-import * as path from 'path';
-
-import { eslintPluginDirectory } from '../../utils/rules';
-import type { RuleDocsPage } from '../RuleDocsPage';
-
-export function insertSpecialCaseOptions(page: RuleDocsPage): void {
- if (page.file.stem !== 'ban-types') {
- return;
- }
-
- const detailsElement = page.children.find(
- (node): node is mdast.Parent =>
- (node as mdast.Node & { name: string }).name === 'details' &&
- (node as mdast.Parent).children.length > 0 &&
- ((node as mdast.Parent).children[0] as { name: string }).name ===
- 'summary',
- );
-
- if (!detailsElement) {
- throw new Error('Could not find default injection site in ban-types');
- }
-
- const defaultOptions = /^const defaultTypes.+?^\};$/msu.exec(
- fs.readFileSync(
- path.join(eslintPluginDirectory, 'src/rules/ban-types.ts'),
- 'utf8',
- ),
- )?.[0];
-
- if (!defaultOptions) {
- throw new Error('Could not find default options for ban-types');
- }
-
- detailsElement.children.push({
- lang: 'ts',
- type: 'code',
- value: defaultOptions,
- } as mdast.Code);
-}
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy