Skip to content

Instantly share code, notes, and snippets.

@CliffCrerar
Last active February 9, 2024 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CliffCrerar/e6246beee1135dc34957d8a212a70df6 to your computer and use it in GitHub Desktop.
Save CliffCrerar/e6246beee1135dc34957d8a212a70df6 to your computer and use it in GitHub Desktop.
Demonstrating reflection in typescript
// 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