Unfortunately, you’re 100% correct — if there was a lot of fields, you’d have to (if you wanted certainty) check every field.

I feel like for exactly that reason, this example is kind of eh. I’ve known about the “is” syntax and have used it before, but I was struggling to find a great example.

A better (as in, more practical but less showcase-y) example maybe would be checking if a “string | undefined” is a string.

Either way, I wouldn’t say that this moves it to runtime — after you do the is check, your compiler tells you that it’s whatever object the “is” turns out to be so you have compile time safety :)

Developer passionate about learning and creating things. Writing to help others learn.