microsoft / microsoft/reflect-metadata
Losing metadata
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3.4k
- Forks
- 190
- Avg merge
- 13h 52m
- Merged PRs (30d)
- 1
Description
Hello,
I've been trying to use this module using typescript for the decorators. I seem to keep losing my data and it's confusing me a little bit. Upon creating a small test, I found some odd behavior I wasn't expecting (I assume the problem here is me).
Whenever I put a decorator on a property, the decorator doesn't get the class as target. I have to use target.constructor to get it. But when I put the decorator on the class itself, it does seem to get the class.
Code speaks a thousand words, so:
export function field() {
return (target:Object, property:string) => {
console.log(target, target.constructor);
};
}
@field() // Log above: [Function: Field] [Function: Function]
export class Field {
@field() // Log above: {} [Function: Field]
public property:any;
}
This confuses me. How can I always get the metadata of a class (including properties) if I always get a different target? Am I missing something on how this should be used?
Thank you for your time.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files or tests are named. Start with the TypeScript decorator examples in the issue and compare class and property decorator targets with the reflect-metadata API documentation. Done means establishing whether the differing targets are expected and clarifying how class and property metadata should be accessed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100