-
Notifications
You must be signed in to change notification settings - Fork 12.8k
loading, declaration and execution phases of modules and cyclic references problem ? #7282
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
Comments
@casser so I'm having a hard time reading through this post and finding the question 😄 - can you clarify what exactly you're asking here? |
I just realize that links was broken, sorry :) Question: Examples above are bugs or expected behaviors ? new Class(); //TypeError: Cls is not a constructor
class Class {
constructor(){
console.info("Created")
}
} Expected behavior:
Actual behavior: Demo
function Field(target,key,desc?){
console.info(Reflect.getMetadata("design:type",target,key).name)
}
class One {
@Field field:Two;
}
class Two {
@Field field:One;
} Expected behavior:
Actual behavior: Demo
Look At this repo for sources |
Ah, gotcha. @rbuckton would know a lot better about the decorators. Though, is #4114 related? As for using a class before its definition, yes, we should be reporting an error. See #21, #4341, and #5207. Apparently there was a fix out for it, but it was never taken in (#4343). @mhegazy what's going on with that? |
This is a known issue with the |
Any solution to this? How can I wrap values of metadata in a functions? It's very blocking for any project with decorators that have circular references. |
This question is related to TypeScript, ES6, SystemJs and ReflectJs specs, but I would like to know your thoughts about it.
So for a function declarations the sequence of code is not important, but for classes it is:
Example with single module
A more complex example when classes located in different modules and have cross references in declaration phase like:
Example with multiple modules and static references
so this is throwing error when trying to create
One
instace, the expectation is to haveOne
declared at the time of exection .This can be hacked by using some cached getters, which can be somehow used to solve the main problem in runtime(loader) :
I have prepared some demo to show hack on this problem, you can see bellow
Expected behavior:
Create and instance of
Cls
and out put it without errors.Actual behavior:
Throws a
TypeError
because of undeclared classExample of cyclic references problem in decoration phase
The other example is annotators cyclic references problem.
I think this is IMPORTANT because
Dependecy Injection (java guice)
,ORM's
orSerialization
frameworks will use this feature deeply, and user code can contain cross referenced types.So the main reason for this problem is that declaration, decoration and execution phases of classes mixed in output.
Potencial hack for this can be generate closure instead of direct type referance in metadata like:
which can be adjusted after module execution, but I think this is just a hack, and the right way will be finnaly define
specification about Loading > Declaration > Annotation > Decoration and Execution phases of runtime which will support cyclic references.
Any thoughts ?
PS: AND AGAIN THANKS FOR
TYPESCRIPT
:)The text was updated successfully, but these errors were encountered: