All posts

I Mass-Replaced 'any' With 'unknown' And Started A Civil War

The codebase had 847 instances of any. I had mass-replace and a dream.

Before

function processData(data: any): any {
  return data.map((x: any) => x.thing?.stuff ?? 'idk');
}

This code worked. It shipped. Customers paid money for it. But it haunted me.

The Plan

# What could go wrong?
find . -name "*.ts" -exec sed -i 's/: any/: unknown/g' {} \;

What Went Wrong

error TS2571: Object is of type 'unknown'.
error TS2571: Object is of type 'unknown'.
error TS2571: Object is of type 'unknown'.
# ... 2,847 more errors

Turns out unknown is any’s responsible older sibling who actually checks your work.

The Aftermath

Half the team thinks I’m a hero. Half the team has mass-replaced my changes back to any. We don’t talk about it in standups.

Lessons Learned

  • any is not a type, it’s a lifestyle
  • unknown requires you to prove you know what you’re doing
  • Some battles aren’t worth fighting before coffee