// read it
function genericsTypes<T, R>(list: T[], param2: R): T {
console.log(param2);
return list[0];
}
// extending genrics types
interface AnyKindOfObject {
what: string;
}
interface reuseableTypes<T extends object> {
entity: T;
}
const d: reuseableTypes<AnyKindOfObject> = { entity: {what : "wert"} };
console.log(d.entity.what); // Compile
// extends
interface ObjectWithId {
id: number;
what: string;
}
interface AnyKindOfObject {
what: string;
}
interface ReusableInterface4<T extends { id: number }> {
entity: T;
}
const e: ReusableInterface4<AnyKindOfObject> = { entity: { id: 5, what: 1 } }; // Doesn't compile
const f: ReusableInterface4<ObjectWithId> = { entity: { id: 1, what: "1" } }; // Compile
const g: ReusableInterface4<string> = { entity: "test" }; // Doesn't compile