Add type safety checks.

Because people are sometimes naughty.