Proper null check for union types