-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Treat in operator as type guard #10485
Copy link
Copy link
Closed
Labels
Effort: DifficultGood luck.Good luck.Help WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Metadata
Metadata
Assignees
Labels
Effort: DifficultGood luck.Good luck.Help WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript
Inspired by #10421
The
inoperator could trivially be seen as a type guard:Basically, for a
n in xwherenis a string literal or string literal type andxis a union type, the "true" arm narrows to types which have an optional or required propertyn, and the "false" arm narrows to types which have an optional or missing propertyn.