Did you used TypeVar correctly? Here is an example
from typing import Sequence, cast, TypeVar, Type
T = TypeVar("T")
def map_cast(T: Type[T], seq: Sequence) -> Sequence[T]:
"""Cast a sequence of elements to a sequence of elements of given type."""
return [cast(T, x) for x in seq]
a = map_cast(str, [1, 2, 3]) # a will have type hint is Sequence[str]
print(a)