Add type_check callback

Fixes #196.

Like #197, but merging into v1.3.0 instead of master.