Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__metadata should register function that returns type instead of literal type #19563

Open
pie6k opened this issue Oct 29, 2017 · 7 comments
Open
Labels
Domain: Decorators The issue relates to the decorator syntax Revisit An issue worth coming back to Suggestion An idea for TypeScript

Comments

@pie6k
Copy link

pie6k commented Oct 29, 2017

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?

@mhegazy mhegazy added the Domain: Decorators The issue relates to the decorator syntax label Oct 30, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Oct 30, 2017

This is already referenced in #14971

@mhegazy mhegazy added Revisit An issue worth coming back to Suggestion An idea for TypeScript labels Oct 30, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Oct 30, 2017

We plan on revisiting some of the decorator decisions as we implement the new decorator proposal

@pie6k
Copy link
Author

pie6k commented Oct 31, 2017

@mhegazy I understand it might be hard to answer - but do you have any, even rough estamine on that? It's something thats quite urgent for my project :)

@mhegazy
Copy link
Contributor

mhegazy commented Oct 31, 2017

I do not have an ETA at the moment.

@bolu
Copy link

bolu commented Aug 1, 2018

Hi, is there any update on the ETA of this? I can imagine some simple changes that would make things work. For example, emit all the decorators at end of file. Or after last class defined in the file.

@keatkeat87
Copy link

keatkeat87 commented Oct 27, 2018

today i change my tsconfig target to es2015, this problem come out.
Error: SomeClass is not defined
any update or alternative work around ?
and why target es5 work fine ?

@BeSpunky
Copy link

Any developments? I'm stuck with the same issue...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Decorators The issue relates to the decorator syntax Revisit An issue worth coming back to Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants