Last active
February 9, 2024 06:49
-
-
Save CliffCrerar/e6246beee1135dc34957d8a212a70df6 to your computer and use it in GitHub Desktop.
Demonstrating reflection in typescript
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
// reflection in typescript | |
const fida = { | |
fName: 'Fida', | |
lName: 'Haq', | |
age: 28 | |
} | |
class ReflectionClass { | |
[property: string]: string | number | |
constructor(obj: any) { | |
Object.keys(obj).forEach(key => this[key] = obj[key]) | |
} | |
public static init(obj: any) { | |
return new ReflectionClass(obj) | |
} | |
} | |
const person = ReflectionClass.init(fida) | |
console.log(person); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment