TypeScript

ts/no-explicit-any

Type values with a real type or unknown (then narrow), never any.

moderatestaticfe-typescript

Why

any switches type checking off for the value and for everything it flows into: a typo in a property name, a missing await or a wrong argument all compile and fail at run time. One any in an API helper spreads to every component that uses its result.

Fix

Use the real type, a generic, or unknown and narrow it before use (typeof, instanceof, in, a type guard, or a schema validator at the boundary). In catch (err), leave the type off: with strict it is unknown. For a third-party gap, write a small declaration instead of any.

Examples

// bad
function total(items: any) { return items.reduce((sum: any, i: any) => sum + i.price, 0) }
// good
function total(items: { price: number }[]) { return items.reduce((sum, i) => sum + i.price, 0) }

Sources

Facts

Id
ts/no-explicit-any
Severity
moderate
Check
static checked in the source by audit
Applies to
jsx vue svelte astro
Only in projects with
typescript
Taught by the skill
fe-typescript TypeScript
Since version
0.1.0

Rule file on GitHub

Read it in the terminal

npx github:dawidolko/frontend-skills explain ts/no-explicit-any