Added contracts for type conversion.

@bsoetaer