Skip to content

Commit

Permalink
docs: add caveats to no-explicit-any docs (#7805)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Oct 26, 2023
1 parent 0bb25cb commit 3300fa1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"nocheck",
"noninteractive",
"nullish",
"onboarded",
"OOM",
"OOMs",
"parameterised",
Expand Down
15 changes: 12 additions & 3 deletions packages/eslint-plugin/docs/rules/no-explicit-any.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,16 @@ interface Garply {

## When Not To Use It

If an unknown type or a library without typings is used
and you want to be able to specify `any`.
`any` is always a dangerous escape hatch.
Whenever possible, it is always safer to avoid it.
TypeScript's `unknown` is almost always preferable to `any`.

However, there are occasional situations where it can be necessary to use `any`.
Most commonly:

- If your project isn't fully onboarded to TypeScript yet, `any` can be temporarily used in places where types aren't yet known or representable
- If an external package doesn't yet have typings and you want to use `any` pending adding a `.d.ts` for it
- You're working with particularly complex or nuanced code that can't yet be represented in the TypeScript type system

## Related To

Expand All @@ -140,4 +148,5 @@ and you want to be able to specify `any`.

## Further Reading

- TypeScript [any type](https://www.typescriptlang.org/docs/handbook/basic-types.html#any)
- TypeScript [`any` type documentation](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#any)
- TypeScript [`unknown` type release notes](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html#new-unknown-top-type)

0 comments on commit 3300fa1

Please sign in to comment.