TypeScript's 'any' and strict mode explained

TypeScript just hit me with this and I had to sit down 🤯 Here's what's actually happening (and why it broke my brain at first): 1. any is TypeScript's emergency exit It literally tells TypeScript "I don't care, let me do whatever I want." Every time you use it, you're turning off the safety net. It's not strict—it's nothing. 2. never isn't broken, it's brilliant It represents values that literally can't exist. Unreachable code. Functions that never return. It's TypeScript saying "this shouldn't be possible"—and that's the point. 3. Union types force you to prove what you have TypeScript won't assume string | number is a string just because you assigned a string. You have to explicitly check first. It's annoying until you realize it's saving you from runtime crashes. 4. Strict mode makes null visible With strictNullChecks, TypeScript stops pretending null doesn't exist. Now you have to handle it. Painful at first. Life-saving in production. The weirdness isn't a bug. It's TypeScript refusing to let you lie to yourself. Once you get it, you can't go back to JavaScript without feeling nervous. What TypeScript feature confused you the most at first? 👇 #TypeScript #WebDev #JavaScript #Programming #Developer #CodingLife #TechTwitter #100DaysOfCode #DevCommunity #LearnInPublic

  • text

"never" is more useful for meta-programming, since TS meta-programming only gives you conditionals most validation checks go like "IsValid ? T : never" This makes it so the user (the "developer" in this case would be the person who made the meta-programming so I'm calling the developer using it the "user" 😅) knows they passed an unsupported argument. I don't think I've ever seen another practical use.

So true 🔥 TypeScript isn’t being difficult — it’s forcing you to be honest about your code. Once it clicks, there’s no going back 💯

Some linter rules will force you to check type on union values before doing operation on them. Some rules may also restrict use of any type in codebase, maintaining overall good structure.

Union types + narrowing confused me initially. Once I understood that TS makes you prove what you have before using it, my runtime bugs dropped drastically. Annoying at first, priceless later.

See more comments

To view or add a comment, sign in

Explore content categories