mediumWrong PatternsTypeScript
The any escape
A developer asked an AI assistant to fix a TypeScript error on a function that processes webhook payloads from a payment provider. The suggested fix makes the red squiggly line disappear, but a malformed payload now crashes the server instead of being caught at compile time.
webhook.ts
function processPayment(payload: any) {
const amount = payload.data.amount;
const currency = payload.data.currency;
chargeCustomer(payload.customerId, amount, currency);
}What did typing payload as any actually accomplish here?
It turned off type checking for every property access on payload, so a malformed webhook fails at runtime instead of being caught by the compiler.
It made the function run faster since TypeScript skips runtime checks on any-typed values.
It automatically validates the payload's shape against the payment provider's schema.
Nothing changed — any behaves identically to a concrete interface for object property access.