Reputation: 396
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?
Upvotes: 0
Views: 41
Reputation: 396
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
}
Upvotes: 1