Created
October 16, 2024 14:23
-
-
Save ludndev/42a383567957ead5d93d34c4f5f6e088 to your computer and use it in GitHub Desktop.
Metadata Reflection Demo
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
/** | |
* Metadata Reflection Demo by https://github.com/ludndev | |
*/ | |
const reportClass: any[] = [] | |
function report(constructor: Function) { | |
reportClass.push(constructor.name) | |
} | |
@report | |
class MathematicsReportClass { | |
type = "report"; | |
title: string; | |
constructor(t: string) { | |
this.title = t; | |
} | |
} | |
@report | |
class BiologyReportClass { | |
type = "report"; | |
title: string; | |
constructor(t: string) { | |
this.title = t; | |
} | |
} | |
console.log('All report classes', reportClass); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run here :
https://www.typescriptlang.org/play/?#code/PQKhCgAIUhZBTALgQwCbJZASvAZgG3gGNEBLAewDtIAReAW3MgCMBPSAC0UQAcBnAFzBgAc1KIOAV2YA6IuXrB8k1JVTwAblBjbIAAT7x4Azt35DRpPohliJ0uQqUq1m4ABYATMgDMADh8AVgA2AHYATkDQ+DRA1HCfVB93IndcQNxg+AAGPz9tYHBweUprSAAneB5ycsQAYXxkPkFIZEpWAG0AXUgAXkhuotxJShIKakrq2oAKEutyyRIakwAxEbGqAEpIAG8oSAPJmvrG5pkeST4OWap5xcQamUpkenhN8ABfIr0j2uLTvhwDAcBgYUhEPg4KYnJqAvYHRCsHjwPqQABEv0QaIA3PsyIhCCZ5qRKCJcZB9nNEAsluVpogidSSSJtvCDpAJFYZPjCKjEOTIF8vuAflVjv9YZAAEIUfDkESsKHHBqStmI5GojFi2o4vHiQmQYmk8mU27U+41emM8rM1n7BEcLk8lH9fn7IVFObkQgyOUiaYAcgAgvh8BVtYhIEQAfA+AGADTh6Eq5qbXFAA