I have a question regarding the possibility of achieving the following in TypeScript: What I want to accomplish:
- If the
type
is set toinbox
, then theobj
should have the type interfaceIInbox
. - If the
type
is set tosent
, then theobj
should have the type interfaceISent
.
interface IInbox {
}
interface ISent {
}
class MailClient {
delete(type: "inbox" | "sent", obj: IInbox | ISent) {
}
}
let client = new MailClient();
client.delete('inbox', <ISent>{}); // This should result in a compile error