I'm trying to recreate something in TypeScript that works in C#.
In the code below, I was expecting both response1 and response2 to be a Promise<number>, but response1 doesn't seem to infer the generic type correctly.
Is this possible? Or is it just something that TypeScript cannot do?
interface IRequest<TResponse> {}
interface MyRequest extends IRequest<number> {
id: string;
}
function execute<TResponse>(request: IRequest<TResponse>): Promise<TResponse>{
return Promise.reject("not implemented");
}
// const response1: Promise<{}>
const response1 = execute(<MyRequest>{
id: "123"
});
// const response2: Promise<number>
const response2 = execute(<IRequest<number>>{
id: "123"
});