Typescript Interface - Possible to make "one or the other" properties required?
<p>Possibly an odd question, but I'm curious if it's possible to make an interface where one property or the other is required.</p>
<p>So, for example...</p>
<pre><code>interface Message {
    text: string;
    attachment: Attachment;
    timestamp?: number;
    // ...etc
}

interface Attachment {...}
</code></pre>
<p>In the above case, I'd like to make sure that either <code>text</code> or <code>attachment</code> exists.</p>
<hr />
<p>This is how I'm doing it right now. Thought it was a bit verbose (typing botkit for slack).</p>
<pre><code>interface Message {
    type?: string;
    channel?: string;
    user?: string;
    text?: string;
    attachments?: Slack.Attachment[];
    ts?: string;
    team?: string;
    event?: string;
    match?: [string, {index: number}, {input: string}];
}

interface AttachmentMessageNoContext extends Message {
    channel: string;
    attachments: Slack.Attachment[];
}

interface TextMessageNoContext extends Message {
    channel: string;
    text: string;
}
</code></pre>