title: Typescript Assert Field Value
body: <p>I'm currently using <a href="https://github.com/stephenh/ts-proto" rel="nofollow noreferrer">https://github.com/stephenh/ts-proto</a> to generate TypeScript types from protobuf messages using type unions for <code>oneOf</code> fields.</p>
  <p>A sample type can be shown like this:</p>
  <pre><code>export interface Milestone {
    milestoneLabel?: 
       { $case: 'milestoneType', milestoneType: MilestoneType } |
       { $case: 'customMilestone', customMilestone: CustomMilestone };
    targetDate: Date | undefined;
  }
  </code></pre>
  <p>Now, later in the code, I want to have a function like this:</p>
  <pre><code>export function getCustomMilestones(milestones: Milestone[]): Milestone[] {
    return milestones.filter(milestone =&gt; milestone.milestoneLabel?.$case === 'customMilestone');
  }
  </code></pre>
  <p>Problem is, the TypeScript language server / compiler doesn't understand that the return type of this function has a filter on the type union, so I need to assert the <code>$case</code> again when trying to read that field.</p>
  <p>Is there a way to tell the compiler the output of the function has a specific type set?</p>