48

Coworker: I give up! Please help me!

Me: What's up?

C: Take a look at this. I have this function here that gets the tab index and I'm passing it to the Tabs component over there. I'm logging the index and as you can see it's 3, but the Tabs component isn't working. However if I replace the function call with a 3 it works!

Coworker 2: While you were explaining all that, shellbug already thought about at least 3 reasons why that isn't working.

Me: **sighs** Of what type is the value that function is returning?

C: **stares at me for a few seconds** It's a number.

Me: Are you sure?

C: Well, it's returning 3.

Me: Please do a typeof.

It was string.

Comments
  • 11
    JavaScript really encouraged bad practices, should use typescript to prevent these types of problems
  • 4
    @hexc we use flow. The function's return type was number. It was not returning a number and flow didn't catch that error. I'm pretty sure typescript wouldn't either, but I might be wrong.
  • 2
    @shellbug with TypeScript you can specify function return type. That said it acts kinda like a fancy linter, so if the data is dynamically generated at runtime it won't catch it. (Not sure if that's the case with flow, as I've never used it.)
  • 2
    @hexc flow works pretty much the same way.

    As I said, the function's return type was set to number but the function was actually returning a string.
  • 15
    Tools don't replace thinking
  • 2
  • 1
  • 1
    Same issue with Python.
    Getting "27" from reading a text file: int
    Getting "27" from an internal variable: string.... Fuck off
Add Comment