from typing import Optional


def extract_ext(filename: Optional[str]) -> str:
    """Extract filename from extension.

    >>> extract_ext('test.txt')
    'txt'

    >>> extract_ext('test')
    ''

    >>> extract_ext('test.txt.bak')
    'bak'
    """
    if not filename:
        return ''

    parts = filename.rsplit('.', maxsplit=1)
    if len(parts) == 1:
        return ''

    return parts[-1].lower()