I would like to write generic function which accepts generic argument e.g Data<string, number>
here is the code:
interface Data<T,R> {
a:T;
c:R;
}
function foo(
data: Data<string, number>
){
return test(data)
}
//this func should be generic
function test<?, T extends Data<?, ?>>(
data: T,
): T {
return data
}
any ideas?
CodePudding user response:
here you go:
interface Data<T,R> {
a:T;
c:R;
}
function foo(
data: Data<string, number>
){
return test(data)
}
//this func should be generic
function test<T,R>(
data: Data<T,R>,
): Data<T,R> {
return data
}
