Complete the code to declare a generic interface named Container.
interface Container<[1]> {
value: T;
}The generic type parameter T is used to define the type inside the interface.
Complete the code to create a variable of type Container holding a number.
const numberContainer: Container<[1]> = { value: 42 };
string when the value is a number.any which is less specific.We specify number as the generic type to hold a number value.
Fix the error in the function signature to accept a generic Container.
function getValue<[1]>(container: Container<T>): T { return container.value; }
The generic parameter T must match the one used in the parameter type Container<T>.
Fill both blanks to create a generic interface Pair with two types.
interface Pair<[1], [2]> { first: [1]; second: [2]; }
The generic parameters A and B represent the types of the two values in the pair.
Fill all three blanks to create a function that returns the first element of a generic Pair.
function getFirst<[1], [2]>(pair: Pair<[3], B>): A { return pair.first; }
The function uses generic parameters A and B matching the Pair interface. The parameter pair is typed as Pair<A, B> and the return type is A.