Navigation Menu

Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ref typings for IntrinsicElements. #2070

Merged
merged 2 commits into from Oct 30, 2019
Merged

Improve ref typings for IntrinsicElements. #2070

merged 2 commits into from Oct 30, 2019

Conversation

loucyx
Copy link

@loucyx loucyx commented Oct 30, 2019

This change adds the corresponding constructor type for all IntrinsicElements in JSX, improving ref types, for example the anchor tag now has the HTMLAnchorElement type in it's ref.

This was created with a simple JS script that extracts the constructor.name of every element in the

Object.keys(/* Object with HTMLIntrinsicElements */)
  .map(tag => document.createElement(tag))
  .map(
    ({ constructor, tagName }) =>
      `${tagName.toLowerCase()}: HTMLAttributes<${constructor.name}>;`
  )
  .join("\n");

After running tests I spotted an issue with the preact.tsx test in the ts directory that wasn't detected previously due to the lack of typing in IntrinsicElements. A ref can be an Element or null, but that wasn't being considered in the types of the test.

This is my first PR in here, I hope I'm not messing anything up 馃槃

@coveralls
Copy link

coveralls commented Oct 30, 2019

Coverage Status

Coverage increased (+0.1%) to 99.891% when pulling c9f5dcb on lukeshiru:better-jsx-refs into 87b945b on preactjs:master.

@loucyx
Copy link
Author

loucyx commented Oct 30, 2019

Ugh, I used prettier accidentally on preact.tsx, rolling that back X_X

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukeshiru Woa, that's super awesome!! We just merged prettier into master this morning, so you're good to go to use it for formatting 馃憤 Can you rebase against that and run prettier on your changes? Apart from that it's ready to be merged 馃帀 Again, thank you so much for the PR 馃挴

@loucyx
Copy link
Author

loucyx commented Oct 30, 2019

@marvinhagemeister I did a rebase on my side and applied the prettier formatting. Let me know if anything else is missing and I'll update accordingly 馃槃

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! This is so good 馃槏 Thank you so much for your PR 馃帀 馃挴

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants