from typing import Type
from typing import Union


def parse_number(s: str, t: Type) -> Union[int, float, None]:
    """
    Parse a string into a number.
    :param s: the string.
    :param t: the type of the number, int or float.
    :return: the parsed number if success, else None.
    """
    try:
        return t(s)
    except (TypeError, ValueError):
        return None