Component: add AbstractComponent to separate Schema-constructable and raw component#251
Component: add AbstractComponent to separate Schema-constructable and raw component#251DavidPeicho wants to merge 1 commit intoecsyjs:devfrom
Conversation
|
Our intent for now is to keep schemas in the core I agree the property and schema types can be repetitive when using typescript, but as soon as you factor in everything else that the schemas do for you at runtime, the amount of boilerplate is negligible. We also don't really want to introduce another class into the component prototype chain. That will just make things slower. If your issue with the current design is type safety then we should discuss solutions around that. I think there is a decent way to write type-safe components right now with a little bit of boilerplate. See this example. If you have ideas for improvements to this pattern, we'd love to hear them! It is a little repetitive. |
|
I still feel that fundamentally, a |
Hi,
I quickly worked on adding a way to simplify schema-constructable component, as well as their typings.
Why?
Before, constructing a component using its schema was made at runtime, see here.
Separating the schema-constructable component versus raw component directly on the class makes the component a bit more cleaner I believe. From a TypeScript point of view, it also simplifies things as we can now pass a custom
Propertiesobject forAbstractComponent(see here), while still being able to keep the previous schema properties type on "normal" component (see here).This PR solves mostly TypeScript issues rather than logic issues. It's really hard to construct component and keep types as safe as possible with the current design.
Improvements
It's highly possible that this design has some issues. If you think it's a good idea to start with we can go this route, and improve it with the community feedback.