from typing import Optional


def time_str_to_ms(time: str) -> Optional[int]:
    """
    Convert time string in 00:00.000 format to milliseconds.
    If it fail return None
    """

    try:
        minutes, second_and_ms = time.split(":")
        second, ms = second_and_ms.split(".")

        total_ms = int(minutes) * 60_000
        total_ms += int(second) * 1000
        total_ms += int(ms)

    except ValueError:
        return None

    return total_ms