TypeScript | Generics in TypeScript | Question2

Last Updated :
Discuss
Comments

Which of the following is a correct example of a generic function?

TypeScript
function identity<T>(value: T): T {
    return value;
}


The function uses a generic type <T> for flexibility.

<T> is unnecessary and makes the function invalid.

The identity function is not generic.

The identity function must define a fixed type for T.

Share your thoughts in the comments