from typing import Dict
from typing import Optional


def parse_and_validate_env_vars(env_vars: Dict[str, str]) -> Optional[Dict[str, str]]:
    """Parses and validates a user-provided 'env_vars' option.

    This is validated to verify that all keys and vals are strings.

    If an empty dictionary is passed, we return `None` for consistency.
    """
    assert env_vars is not None
    if len(env_vars) == 0:
        return None

    if not (
        isinstance(env_vars, dict)
        and all(
            isinstance(k, str) and isinstance(v, str) for (k, v) in env_vars.items()
        )
    ):
        raise TypeError("runtime_env['env_vars'] must be of type Dict[str, str]")

    return env_vars