Skip to content

docs(eslint-plugin): [typedef] deprecate the rule #11202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions packages/eslint-plugin/docs/rules/typedef.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import TabItem from '@theme/TabItem';
>
> See **https://typescript-eslint.io/rules/typedef** for documentation.

:::caution

This is an old, deprecated rule.
It will be removed in a future major version of typescript-eslint.

Requiring type annotations unnecessarily can be cumbersome to maintain and generally reduces code readability.
TypeScript is often better at inferring types than easily written type annotations would allow.

**Instead of enabling `typedef`, it is generally recommended to use the `--noImplicitAny` and `--strictPropertyInitialization` compiler options to enforce type annotations only when useful.**

:::

TypeScript cannot always infer types for all places in code.
Some locations require type annotations for their types to be inferred.

Expand All @@ -30,15 +42,6 @@ class ContainsText {

> To enforce type definitions existing on call signatures, use [`explicit-function-return-type`](./explicit-function-return-type.mdx), or [`explicit-module-boundary-types`](./explicit-module-boundary-types.mdx).

:::caution

Requiring type annotations unnecessarily can be cumbersome to maintain and generally reduces code readability.
TypeScript is often better at inferring types than easily written type annotations would allow.

**Instead of enabling `typedef`, it is generally recommended to use the `--noImplicitAny` and `--strictPropertyInitialization` compiler options to enforce type annotations only when useful.**

:::

## Options

For example, with the following configuration:
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-plugin/src/configs/eslintrc/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ export = {
'@typescript-eslint/strict-boolean-expressions': 'error',
'@typescript-eslint/switch-exhaustiveness-check': 'error',
'@typescript-eslint/triple-slash-reference': 'error',
'@typescript-eslint/typedef': 'error',
'@typescript-eslint/unbound-method': 'error',
'@typescript-eslint/unified-signatures': 'error',
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'error',
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-plugin/src/configs/flat/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ export default (
'@typescript-eslint/strict-boolean-expressions': 'error',
'@typescript-eslint/switch-exhaustiveness-check': 'error',
'@typescript-eslint/triple-slash-reference': 'error',
'@typescript-eslint/typedef': 'error',
'@typescript-eslint/unbound-method': 'error',
'@typescript-eslint/unified-signatures': 'error',
'@typescript-eslint/use-unknown-in-catch-callback-variable': 'error',
Expand Down
4 changes: 4 additions & 0 deletions packages/eslint-plugin/src/rules/typedef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export default createRule<Options, MessageIds>({
name: 'typedef',
meta: {
type: 'suggestion',
deprecated: {
deprecatedSince: '8.33.0',
message: 'This is an old rule that is no longer recommended for use.',
},
docs: {
description: 'Require type annotations in certain places',
},
Expand Down
Loading