Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I guess it's because most people think of this as "the property is optional, when it's there, it's of type int".


I can’t test type narrowing right now, but I suspect that (“age” in obj) or a similar hasOwn() etc wouldn’t narrow it to just (type) in neither of these languages. It is correct to write “age?” under your assumption, e.g. for settings objects, but sometimes a property is or must be always there.

Maybe the reason is that this distinction creates an unnecessary complexity at matching semi-optional types together, because programs do not usually care about exists/defined distinction.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: