Add type_check callback

Fixes #196.

- [x] Add tests.
- [ ] Add documentation.