18

Have a function that takes parameters and then performs a switch statement to determine what function to call next with those same parameters. One of those parameters is a Union type.

During CR, my reviewer said they’d like if instead of returning the function per case, I instead assigned a handler to the value of the function per case and then returned that handler at the end of the switch. Simple change, right? Only snafu, I’m casting one of the parameters on a per-case basis.

Somehow, through no fucking change of my own, TypeScript in its wisdom has decided that the type of that value by the time I call the next function is a fucking Intersection.

WHY THE FUCK DO YOU THINK IT’S AN INTERSECTION?! I’m fucking casting it per case! I’m ensuring it’s the right type for the next function called on a per case basis!

…. And that, my friends, is how I wasted a day with a stupid refactor that was ultimately just scrapped because no one could figure out how to make it work.

Goddamn fucking TypeScript. I

Comments
  • 4
    I'd like to waste my time, can I take a look at the code?
  • 3
    I'm interested, I work with typescript and haven't had anything upset me too bad so far. What other gripes you got?
  • 2
    This looks like an opportunity to use the strategy pattern...

    And as TypeScript is purely shape-typed, you might want to have an otherwise useless property containing a type tag on your objects - so you have something to check for in your type check functions.
Add Comment