-
Notifications
You must be signed in to change notification settings - Fork 11
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
[Question] getType returns either Invalid (using getType<Type>()) or unkonwn (using getType(var)) #93
Comments
You can use ad3) It should not be required. It should be generated into the project root folder; based on tsconfig. EDIT: But the main problem, in my opinion, is with the transformer. The |
@zerobytes If you prepare some repro, I can help you to configure it. |
hey @Hookyns |
Updated tsconfig with baseUrl and imports on metadata.typelib seem correct now |
Ok. I wonder if it is really necessary that metadata.typelib remains on root instead of at the src folder. Overall, this project really interests me, as there is absolutely nothing as good as this (in terms of features) available and I have been a framework creator since the early 2000's, and reflection is a must. I am currently creating a component that will create a form based on a model, with any nesting complexity. That said, I would like to collaborate on the project if you're open to it. |
This is quite complex topic. I got the flu so I am not capable to cover everything right now and I'm responding from a phone. Main points:
So you have to configure transformer in projects where you want to use getType function. If it will be only in the library, then you don't have to configure it in the React app. Well.. it's also required if you want to use the feature with runtime generic types - eg. your lib exports something like export function getForm<TModel>() {
return generateForType(getType<TModel>());
} , your users also have to configure transformer. So in such case the eject will be required. Webpack is supported by current tst-reflect package (this repository; RTTIST is in custom repository - it's closed alpha) but I wouldn't use it for new tools like you are creating. RTTIST transformer is written in Rust. It is TS to TS transformer so it is possible to use it as webpack loader. You can create webpack loader plugin. 🙂 Webpack has low prio for me because everybody use Vite etc. these days. Note: I will post some examples when I get to PC. I can also invite you to RTTIST repo. |
EDIT: It is possible without eject. I'm preparing demo. |
I recently installed rttist in my typescript library.
It's a very simple model library, where everything is just typescript classes and enums.
the generated metadata looks good.
the library is installed in a react application, where rttist is also installed
In the react app, I am calling getType, that is exported from the library through the metadata.typelib located in the library
Library index.ts
React App
The issue is, when I log getType it is either "Invalid Invalid [::invalid::Invalid]" or "Unknown unknown [#unknown]".
For reference, ids are respectively "::invalid::Invalid" and "#unknown"
If I log Metadata.getModules(), all the library modules are correctly there.
If I log Metadata.getTypes(), all the library types are correctly there.
1- I ran rttist init in the library
2- I ran rttist generate in the library
3- I moved the metadata.typelib to src
4- I exported all exports from metadata.typelib in my index.ts
5- I installed rttist in the react app
6- I imported the getType and Metadata that are being exported from the library
7- getType does not work as expected
The text was updated successfully, but these errors were encountered: