Можливо, дивне запитання, але мені цікаво, чи можливо зробити інтерфейс, де потрібна одна або інша властивість.
Так, наприклад ...
interface Message {
text: string;
attachment: Attachment;
timestamp?: number;
// ...etc
}
interface Attachment {...}
У наведеному вище випадку я хотів би переконатися, що це textабо attachmentіснує.
Сподіваємось, це має сенс.
Спасибі заздалегідь!
Редагувати: Ось як я це роблю зараз. Думав, це трохи багатослівно (набравши боткіт для слабини).
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;
}