Preserve nil values when typecasting