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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: createElement & h types #4578

Merged
merged 3 commits into from
Nov 29, 2024
Merged

fix: createElement & h types #4578

merged 3 commits into from
Nov 29, 2024

Conversation

rschristian
Copy link
Member

Closes #4577

Seems like a bit of a shame, essentially the type falls through to just match against a string and offer no real type checking, but it's seemingly what React does.

@coveralls
Copy link

coveralls commented Nov 29, 2024

Coverage Status

coverage: 99.616%. remained the same
when pulling 09b8b15 on fix/h-types
into db47ab6 on main.

type: keyof JSXInternal.IntrinsicElements,
type: keyof JSXInternal.IntrinsicSVGElements,
Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, drive-by change.

I couldn't find a situation in which this actually made a difference, as createElement/h seemingly always falls back to a very loose overload that allows anything, but we extracted out IntrinsicSVGElements a bit more than a year ago and so we should be using it.

@JoviDeCroock
Copy link
Member

Let's add a ts-test

@rschristian
Copy link
Member Author

rschristian commented Nov 29, 2024

Unfortunately our ts-tests seem to be not working correctly. This is an error in the TS playground, but not in our test suite:

h('a', { href: 'https://example.com' });

I have no earthly idea why at the moment, hence why I held off on a test. I don't understand what differentiates a & href from option & value. Maybe I'm being daft, let me know if that makes any sense to you.

@JoviDeCroock
Copy link
Member

JoviDeCroock commented Nov 29, 2024

The TS-playground test from the issue replicated for me in our tests, I based my comments off of those tests

@rschristian
Copy link
Member Author

Yeah that one does for me too, but seemingly not other equivalent tests? Which is why I'm confused.

I can copy/paste that and move on, just don't understand what exactly is diverging & what we're testing. Something seems off.

@JoviDeCroock
Copy link
Member

Hmm, that's odd, the type-checking used to work very well and I think with the examples I gave still does. Not sure what changed though, to your point

@rschristian
Copy link
Member Author

OH nvm, it's falling into the HTMLAttributes & SVGAttributes overload. Somehow didn't notice that

@rschristian rschristian merged commit cf6942d into main Nov 29, 2024
5 checks passed
@rschristian rschristian deleted the fix/h-types branch November 29, 2024 07:12
@JoviDeCroock JoviDeCroock mentioned this pull request Dec 1, 2024
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.

TS error for h() function overload match when element properties do not include global attribute
3 participants