Skip to content

Instantly share code, notes, and snippets.

@tkssharma
Created October 28, 2018 02:26
Show Gist options
  • Save tkssharma/4b5cc7396931196b2ce208d918fb3680 to your computer and use it in GitHub Desktop.
Save tkssharma/4b5cc7396931196b2ce208d918fb3680 to your computer and use it in GitHub Desktop.
interface MyCustomTypeA {
test: string;
}
interface MyCustomTypeB {
anything: boolean;
}
interface ReusableInterface3<T> {
entity: T;
}
const ri3a: ReusableInterface3<MyCustomTypeA> = { entity: { test: "yes" } };
const ri3b: ReusableInterface3<MyCustomTypeB> = { entity: { anything: true } };
const ri3c: ReusableInterface3<number> = { entity: 1 };
class MyClass4<T> {
// Class
list: T[] = [];
public displayFirst(): void {
const first: T = this.list[0]; // Variable
console.log(first);
}
}
// read it
function extractFirstElement<T, R>(list: T[], param2: R): T {
console.log(param2);
return list[0];
}
// extending genrics types
interface AnyKindOfObject {
what: string;
}
interface ReusableInterface3<T extends object> {
entity: T;
}
const d: ReusableInterface3<AnyKindOfObject> = { entity: a };
console.log(d.entity.what); // Compile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment