microsoft / microsoft/TypeScript
__metadata should register function that returns type instead of literal type
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Imagine case with circular dependencies
class Car {
@Field owner: Person // !!! Error: Person is not defined.
}
class Person {
@Field car: Car;
}
// car has owner, owner has car
Typescript metadata would be emitted here like
eg.
__metadata('design:type', Person).
As Person is injected for the first time before Person class is initialized, it will result with ReferenceError saying Person is not defined.
If it'd emit metadata like:
__metadata('design:type', () => Person)
it'd be fine.
Later on, when using Reflect.metadata, it would also need to call meta function instead of just returning the type.
If you think it's good idea, do you have any suggestions about starting point for PR that would implement this change?
Contributor guide
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
Start by tracing the TypeScript compiler path that emits decorator metadata, then inspect how Reflect.metadata consumes the emitted value. Done means the circular Car/Person example avoids the initialization ReferenceError and metadata consumers invoke the deferred type function; the payload names no files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100