Junior — Middle
Do you have experience using generics in development?
sobes.tech AI
Answer from AI
Yes, generic types allow creating components that work with different data types while ensuring type safety and code reusability. In Node.js, using TypeScript or Flow, you can declare functions and classes with type parameters. For example, in TypeScript:
function identity<T>(arg: T): T {
return arg;
}
const num = identity<number>(42); // num will be of type number
const str = identity<string>("hello"); // str will be of type string
This enables writing universal code that adapts to different types without losing type safety.