add type and function for JS errors
return untyped nil in case of no error