ryansolid / dom-expressions

A Fine-Grained Runtime for Performant DOM Rendering
MIT License
885 stars 127 forks source link

(feat) augmentable JSX-Element-type #164

Closed bigmistqke closed 2 years ago

bigmistqke commented 2 years ago

I have been having a lot of fun lately with custom JSX-elements (for example with this little side-project) : JSX are functions and functions can return more then dom-elements or any of the allowed JSXElement-types. Solidjs itself allows this approach, but it is impossible right now to properly type these components as types can not be augmented through declaration.

My proposal is to follow a pattern described here interface XRegistry { A:A B:B C:C } type X= XRegistry[keyof XRegistry]; //... And in the other file declare module "someModule" { interface XRegistry { D:D } }

This way JSXElements could be augmented through a declaration-file as follows declare module 'solid-js/jsx-runtime' { namespace JSX { interface CustomElement { test: string } interface ElementRegistry { CustomElement: CustomElement } } }

It creates identical code if not augmented, and works perfectly as is right now. If you want an example of it in action: (this repo) contains a patch with it working.

(I thought first to make the pull request with Solid, but the tests and builds kept on overwriting my changes, so I realized it was importing the types from here)

bigmistqke commented 2 years ago

oops still a github-noob