Complete the code to declare a generic function that accepts a parameter of any type.
function identity<T>([1]: T): T { return param; }
Complete the code to constrain the generic type to only types that have a 'length' property.
function logLength<T extends [1]>(item: T): number { return item.length; }
Fix the error in the generic function that requires T to have a 'toString' method.
function stringify<T extends [1]>(value: T): string { return value.toString(); }
Fill both blanks to create a generic function that accepts an object with a key K and returns its value.
function getProperty<T, K extends keyof T>(obj: T, key: [1]): T[[2]] { return obj[key]; }
Fill all three blanks to define a generic function that returns the length of a property K of object T, where that property has a length.
function getLength<T, K extends keyof T>(obj: T, key: K): number {
const value = obj[[1]];
if (value && typeof value === [2] && 'length' in value) {
return value.length[3];
}
return 0;
}