from typing import Optional


def parse_opt_int(s: Optional[str]) -> Optional[int]:
    """
    parse_opt_int(s: Optional[str]) -> Optional[int]
    If s is a string, parse it for an integer value (raising a ValueError if
    it cannot be parsed correctly.)
    If s is None, return None.
    Otherwise, raise a TypeError.
    """
    if s is None:
        return None

    if isinstance(s, str):
        return int(s)

    raise TypeError(f"value must be a string or None: {type(s).__name__}")