from typing import Optional


def find_occurrence(string: str, sub: str, position: int, start: Optional[int] = None, end: Optional[int] = None) -> int:
    """
    Similar to `str.find`, but finds the offset of the `position-th` occurrence of `sub` in `string`. 
    If it can't be found, returns -1.
    """
    if len(sub) == 0:
        return 0
    marker: int = 0
    curpos: int = start if start is not None else 0
    if end is None:
        end = len(string)
    while marker <= position and curpos <= len(string): 
        j = string.find(sub, curpos)
        if j < 0 or marker == position:
            return j
        curpos = j + len(sub)
        marker += 1
    # Theoretically we should never get here, but if we do ...
    raise RuntimeError("invalid state")