typecast only if valid