Skip to main content

No Explicit Any

Disallow usage of the any type. Use unknown and narrow with type guards, or define a specific type.

Summary

The no-explicit-any rule reports every occurrence of the any type keyword in type annotations, return types, generics, and type aliases.

Using any disables type checking entirely for that value, defeating the purpose of TypeScript.

Why Use This Rule?

  1. Prevents type safety holes that allow runtime errors to pass through the compiler uncaught.
  2. Encourages the use of unknown with proper type narrowing, which keeps the type system enforced.
  3. Makes the codebase easier to refactor because every value has a meaningful type.

Examples

Configuration

Options

warning

ignoreFiles is an escape hatch for files where this rule genuinely does not apply. It is not intended for routine use.

OptionTypeDefaultDescription
ignoreFilesstring[][]File patterns to skip.

Autofix

Autofix is not available for this rule. Flagged code must be updated manually.

Troubleshooting

  • Error fires on third-party library types — If a dependency's type definitions use any, the error comes from your own code referencing that type. Wrap the value in a named type alias with a more specific type or use unknown.
  • Need any for a legitimate escape hatch — Use the ignoreFiles option to exclude specific files where any is unavoidable.