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?
- Prevents type safety holes that allow runtime errors to pass through the compiler uncaught.
- Encourages the use of
unknownwith proper type narrowing, which keeps the type system enforced. - 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.
| Option | Type | Default | Description |
|---|---|---|---|
ignoreFiles | string[] | [] | 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 useunknown. - Need
anyfor a legitimate escape hatch — Use theignoreFilesoption to exclude specific files whereanyis unavoidable.