I'm wondering if somethings as follows is possible in TypeScript, What I'm trying to achieve:
- If the
typeisinboxthenobjshould be of type interfaceIInbox. - If the
typeissentthenobjshould be of type interfaceISent.
interface IInbox {
}
interface ISent {
}
class MailClient {
delete(type: "inbox" | "sent", obj: IInbox | ISent) {
}
}
let client = new MailClient();
client.delete('inbox', <ISent>{}); // should give compile error