Created
August 4, 2023 06:49
-
-
Save MariusBongarts/63232f23cfb956ef2561f40867217e4f to your computer and use it in GitHub Desktop.
This file contains 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 Context { | |
name: string; | |
metadata: Record<PropertyKey, unknown>; | |
} | |
function setMetadata(_target: any, context: Context) { | |
context.metadata[context.name] = true; | |
} | |
class SomeClass { | |
@setMetadata | |
foo = 123; | |
@setMetadata | |
accessor bar = "hello!"; | |
@setMetadata | |
baz() { } | |
} | |
const ourMetadata = SomeClass[Symbol.metadata]; | |
console.log(JSON.stringify(ourMetadata)); | |
// { "bar": true, "baz": true, "foo": true } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment