microsoft / TypeScript-Handbook

Deprecated, please use the TypeScript-Website repo instead
https://github.com/microsoft/TypeScript-Website
Apache License 2.0
4.88k stars 1.13k forks source link

in operator clarification #1325

Open enumag opened 4 years ago

enumag commented 4 years ago

The in operator documentation says the following:

the "true" branch narrows to types which have an optional or required property n, and the "false" branch narrows to types which have an optional or missing property n.

As a typescript beginner this is very confusing to me. Which branch is executed if the type has an optional property n? The text seems to suggest that both branches are executed which can't be the case.

I'm guessing that for optional properties the in operator returns false if the property value is undefined and true otherwise?

Please rephrase this to make it clear.