-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Function instead of interface name when using Reflect #10711
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
TypeScript types, e.g. interfaces, type aliases, etc.., do not exist at runtime. they are design-time constructs that the compiler uses to check the consistency of the code, and are removed when generating the final JS. The refectMetaData feature only preserves metadata about runtime values. classes do have a runtime value, i.e. the constructor function, whereas interfaces do not. if the compiler knows there is a runtime value packaging the type (classes or enums), then it will use it; if not, it will try find the best "guess". so |
you can find more relevant discussions in #3628 |
I think my problem is about reflection not type checking, And I know all thing that you wrote. I want to know the interface name with reflection and nothing more. I want to replace
it compiles to
|
First, the interface name by itself is not sufficient. the name is not unique. Second, and more importantly, TS has a structural type system, not a nominal one, so the interface name is of inconsequential in this matter, you could pass in an anonymous type that matches the interface, or another interface, etc.. This issue has been discussed in length before, please see issue #3060 (linked from #3628 among others) |
Hi
I've a problem with using reflect in field decorators. I've created a decorator with below signature:
And I use @Inject on fields. It works when field type is class but when field type is interface, it returns
Function
not the name of interface. How can I fix it?The text was updated successfully, but these errors were encountered: