throw TypeError instead of returning undefined

Returning undefined seems like it could introduce hard to spot bugs.