Complete the code to create a generic function that returns the input value.
function identity<T>(value: T): T {
return value;
}The generic function uses value as the parameter name to return it directly.
Complete the code to declare a generic array of type T.
let items: Array<[1]> = [];Using T allows the array to hold elements of the generic type.
Fix the error in the generic function parameter type.
function wrapInArray<T>(value: [1]): T[] { return [value]; }
The parameter type should be the generic type T to match the function's generic parameter.
Fill both blanks to create a generic function that returns the first element of an array.
function firstElement<[1]>(arr: [2][]): [1] { return arr[0]; }
The generic type parameter T is used both to declare the generic and to type the array elements.
Fill all three blanks to create a generic function that maps an array of type T to an array of type U.
function mapArray<[1], [2]>(arr: [1][], func: (item: [1]) => [2]): [2][] { return arr.map(func); }
The function uses generic types T and U to transform an array of T into an array of U.