from typing import Tuple
from typing import Union
import re


def parse_thread_url(url: str) -> Tuple[str, Union[str, None]]:
    """Parses a URL to a thread ID and optionally a post ID."""
    pattern = re.compile(r"(t-[0-9]+)(?:.*#(post-[0-9]+))?")
    match = pattern.search(url)
    if not match:
        raise ValueError("Thread URL does not match expected pattern")
    thread_id, post_id = match.groups()
    return thread_id, post_id