i'm pretty new to typescript and i'm trying to play with nested generics. By now I can't make them work as i would expect, probably i'm missing something obvious. Here is my sample code:
type GenericServiceResponse<T> = {
status: number;
payload: T;
}
type myServicePayload = {
name: string;
surname: string;
}
type myServiceResponse = GenericServiceResponse<myServicePayload>;
class GenericServiceRequest {
callback?: <T>(data:T) => void;
}
let request = new GenericServiceRequest();
request.callback = <myServiceResponse>(data:myServiceResponse) => {
console.info(data.payload.name);
};
The output of the tsc compiler (target es5) is:
main.ts(20,23): error TS2339: Property 'payload' does not exist on type 'myServiceResponse'.