diff --git a/packages/eslint-plugin/docs/rules/no-explicit-any.md b/packages/eslint-plugin/docs/rules/no-explicit-any.md index efec50113734..693700d13912 100644 --- a/packages/eslint-plugin/docs/rules/no-explicit-any.md +++ b/packages/eslint-plugin/docs/rules/no-explicit-any.md @@ -6,7 +6,7 @@ description: 'Disallow the `any` type.' > > See **https://typescript-eslint.io/rules/no-explicit-any** for documentation. -The `any` type in TypeScript is a dangerous "escape hatch" from the type system. +The `any` type in TypeScript is a potentially dangerous "escape hatch" from the type system. Using `any` disables many type checking rules and is generally best used only as a last resort or when prototyping code. This rule reports on explicit uses of the `any` keyword as a type annotation. @@ -158,7 +158,27 @@ interface Garply { ## When Not To Use It -If an unknown type or a library without typings is used +**Difficult-to-represent TypeScript types**. +Some code patterns can be difficult to represent exactly in the TypeScript type system. For example, functional programming concepts such as composing and piping sometimes necessitate using `any`. + +```ts +// eslint-disable no-explicit-any +type a2a = (x: any) => any; +const pipe = (...fns: a2a[]) => (x: any) => fns.reduce((y, f) => f(y), x); +const compose = (...fns: a2a[]) => (x: any) => fns.reduceRight((y, f) => f(y), x); +// eslint-enable no-explicit-any + +type n2n = (n: number) => number; +const g: n2n = n => n + 1; +const f: n2n = n => n * 2; +type n2s = (n: number) => string; +const exclaim:n2s = (n) => `${n}!`; + +const h: n2s = pipe(g, f, exclaim); +const j: n2s = compose(exclaim, f, g); +``` + +**Unknown Types**. If an unknown type or a library without typings is used and you want to be able to specify `any`. ## Related To 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