Created
October 28, 2018 02:26
-
-
Save tkssharma/4b5cc7396931196b2ce208d918fb3680 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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