Generic with a type alias
The placement of your generic type parameter is wrong. You want a generic function (the type parameter to be on the function) not a generic type that happens to be a function. The difference is that a generic function has its type parameters decided when it is invoked. A generic type needs to have its type parameters decided when it is used.
type Options<T> = {
data: T;
};
type MockData = <T>(options: Options<T>) => Promise<{ data: T }>;
export const mockApiCall: MockData = async ({ data }) => {
return new Promise((resolve) => {
setTimeout(() => resolve({ data }), 100);
});
};
Playground Link