generics with function expressions

Solutions on MaxInterview for generics with function expressions by the best coders in the world

showing results for - "generics with function expressions"
Melina
09 Sep 2019
1Generic functions
2
3// Something like the following works fine:
4function foo<T>(x: T): T { return x; }
5
6
7// However using an arrow generic function will not:
8const foo = <T>(x: T) => x; // ERROR : unclosed `T` tag
9
10
11// Workaround: Use extends on the generic parameter 
12// to hint the compiler that it's a generic, e.g.:
13const foo = <T extends unknown>(x: T) => x;
Neele
20 Jul 2020
1Typically a generic funtion is an instance of a class that inherit boht from function  and standard objects .Thus generic functions are both fucntions and ordinary objects
similar questions
queries leading to this page
generics with function expressions