Andrey (azangru) wrote,

Typescript surprises me.

Say we have a function:

What will the type of the return value be? What if there is no colon in the provided string — then bar will be undefined. But typescript has the utmost confidence in the programmer, and is happy to infer that both foo and bar are strings:

This is dangerous! Here, we shall get an undefined is not a function:

Flow behaves the same, by the way.

Recent Posts from This Journal

  • (no subject)

    Course description: In today's business world there are massive goals around diversity and inclusion and you are empowered to lead the way as…

  • Via Reddit

    I didn't know what the operation game was, so I looked it up. The guy, indeed, is clearly awake: I only learnt about charlie horse from King's…

  • (no subject)

    Listened to a talk from YCombinator's Startup School 2013: The tone of the talk is very different from the the tone that's typically employed…

  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.