davesnx / html_of_jsx

Render HTML with JSX

Home Page:https://davesnx.github.io/html_of_jsx/html_of_jsx/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve type-safety of string-based props

davesnx opened this issue · comments

Many attributes are defined as string when in reality (the HTML spec) doesn't allow any string and it defines an enum. There's the case of attributes defined also as a polymorphic typeint or bool as well or more strange

The benefit from moving away from string-based API are:

  • Safety, within a string there could be a typo without noticing it.
  • Learnability. Users might be able to learn about HTML and their APIs.
  • Correctness, generate valid HTML isn't crazy important but it's nice to have a feedback on compile time, also have a positive impact on on-page SEO.

There have been a few efforts on rescript-react to push that direction but didn't land yet (a few comments by @dodomorandi in rescript-lang/syntax#235) and I'm not sure if there's a positive intent to do so.

We have the possibility to do it

Other references:


The plan for this is to check TyXML and https://html.spec.whatwg.org/#global-attributes and manually ensure that most of our attributes make sense.

Doubts

  • How to provide a way to override/discard the issue?
  • How easy is to discover the attrs values?
  • How we can expose Ppx_static_attributes on both the ppx and the runtime? (Maybe merging Jsx.Attributes and Ppx_static_attributes