a more robust type checking for js