-
Notifications
You must be signed in to change notification settings - Fork 49
Typescript: More specific types for children #35
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
Made an issue to see if it can be done at the lint level but I'm not optimistic :P doing this might require doing a non-JSX structure to make it easier to type, so maybe a fork of this library |
Can def happen at runtime with proptypes, and Flow can type it - but TypeScript is unable at the moment (possibility for late june Typescript 4.0 (microsoft/TypeScript#38510 (comment)), but the PR for it has perf issues so potentially not) - discussions at typescript here: |
Typescript allows checking children type https://www.typescriptlang.org/docs/handbook/jsx.html#children-type-checking . I guess this might be used. |
@daliusd that doesn't help unless the children are not actually react elements but just objects or primitives that |
for example to use that, instead of writing an MJML component like <MjmlSection>
<MjmlColumn />
</MjmlSection> You would need to not use JSX for the children and do something like this: <MjmlSection>
{[
{type: "MjmlColumn", contents: []}
]}
</MjmlSection> and |
If project owners are open to migration to TypeScript, I could help migrating all JavaScript into TypeScript in a PR.
|
Hey @o-alexandrov we are thinking about converting this project to a typescript. We are doing a little bit of research currently. Once finished we will let you know. Stay tuned. |
Hey, this project is no longer maintained so if someone wants to do something about it then feel free to fork it. |
This is not necessarily the right place to put this since typings are managed at DefinitelyTyped, but figured it would get more relevant eyeballs here so posting:
One of the great things about MJML is that it validates your email HTML. But it would be even better if some of those validations could occur at compile time instead.
There's a lot of low hanging fruit like "children of mj-sections need to be mj-columns" or "an h1 tag can only be inside of an mj-text instance", which can be checked before even running your code. Would be amazing if those were typed explicitly -
although I am not sure how to type "an instance of a specific component" off the top of my headyeah i don't think it's possible :PExploring other ways it can potentially be done without messing with the API of this library
The text was updated successfully, but these errors were encountered: