// Generic functionfunctionidentity<T>(arg: T): T{
return arg;
}
let result = identity<string>("hello"); // result will be string type// Generic classclassDataContainer<T> {
private data: T;
constructor(initData: T) {
this.data = initData;
}
getData(): T {
returnthis.data;
}
}
let container = new DataContainer<number>(10); // container is of type numberlet data = container.getData(); // data will be of type number