When working with PHP, we can check for a specific instance like this. Check it out here
interface IInterface
{
}
class TheClass implements IInterface
{
}
$cls = new TheClass();
if ($cls instanceof IInterface) {
echo "yes";
}
I have a similar scenario in Typescript and I'm checking it like so.
public handle() {
return (err: any, req: Request, res: Response, next: any) => {
switch (err.constructor) {
case MyException:
var response = err.getResponse();
res.status(500).send(response);
break;
default:
res.status(500).send(err.message);
}
}
}
Instead of using MyException
, now I want to check against IMyException
. Any suggestions on how I can achieve this?