Changing instanceof to typeof