any ne corrige rien. Il éteint la lumière — et le bug revient à l'exécution.any fixes nothing. It turns off the lights — and the bug returns at runtime.
C'est le réflexe qui ouvre le volume : un type récalcitrant, on met any, l'erreur disparaît, on passe à autre chose. Mais any n'est pas un type — c'est l'interrupteur qui débranche le vérificateur. La faute de frappe, le champ absent, la méthode inventée : tout passe. On n'a pas réglé le problème, on a juste éteint l'avertissement. Le bug, lui, attend tranquillement le runtime. C'est l'unsafe de TypeScript.It's the reflex that opens the volume: a stubborn type, you slap any on it, the error vanishes, you move on. But any isn't a type — it's the switch that unplugs the checker. The typo, the missing field, the invented method: all pass. You didn't solve the problem, you just turned off the warning. The bug, meanwhile, quietly waits for runtime. It's TypeScript's unsafe.
function totalPrice(cart: any): number { return cart.items.reduce((s, it) => s + it.prce, 0); // ^ items peut être absent ^ 'prce' : faute de frappe } // aucune erreur : any a éteint TOUTE vérification // 💥 au runtime : cart.items undefined → crash, ou un NaN qui se propage
any ne déplace pas l'erreur, il la rend muette : elle ressurgit identique à l'exécution, loin de l'endroit qu'on relit. Le type réel, lui, fait protester le compilateur là où on écrit la faute.any doesn't move the error, it mutes it: it resurfaces unchanged at runtime, far from the spot you review. The real type makes the compiler protest where you write the mistake.
type Cart = { items: { price: number }[] }; function totalPrice(cart: Cart): number { return cart.items.reduce((s, it) => s + it.prce, 0); // ^ ✗ 'prce' n'existe pas — attrapé } // le bug n'atteint jamais l'exécution
« Est-ce que je connais ce type, ou est-ce que j'abandonne la vérification — et est-ce que je le sais ? » any abandonne en silence. Avant de l'écrire, demande-toi si l'erreur que tu fais taire n'était pas un fait vrai sur ton code."Do I know this type, or am I abandoning the check — and do I know it?" any abandons silently. Before writing it, ask whether the error you're silencing wasn't a true fact about your code.
Le volume du « faire taire le compilateur ». On commence par le pire des silences : celui qui ne dit pas son nom. any ne se contente pas de masquer une erreur — il déteint, et c'est l'objet du chapitre suivant. unknown (4.2) et as (4.3) sont les façons honnêtes de faire ce qu'any fait en douce.The volume of 'silencing the compiler'. We begin with the worst silence: the one that doesn't announce itself. any doesn't just hide an error — it bleeds, which is the next chapter's subject. unknown (4.2) and as (4.3) are the honest ways of doing what any does on the sly.