I prefer not to do the typeof check in code like this. If the user accidentally passes a non-function, they won't get an error message letting them know that they did something wrong.  I'd just do:  if (onCancel) onCancel()

Separately, I think this code would be cleaner if you just defined the two functions as regular nested functions rather than using function expressions and assigning them to variables, especially since you do the assignment inside of a function call where it is kind of unexpected and harder to read.