-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Do these types belong to HTMLAttributes? #4202
Comments
"Standard HTML Attributes", as opposed to Non-standard Attributes, RDFa Attributes, Microdata Attributes, etc., not attributes that exist on every single element type. I think our types are significantly simpler than most other frameworks, though yes, this does mean you can add attributes anywhere you want (as you could with HTML). We might be open to being stricter if someone wanted to work on that? |
I agree with you that the types are simpler than most other frameworks, but in my opinion, allowing HTML tags that are not actually native in an element (even though you could in HTML) is a little counter-intuitive, at least if you expect Typescript to flag an error (like if you come from another framework where this actually happens). As a developer is, of course, my duty to ensure the correct attributes are set and everything works as it should, but it’s definitely nice having a “guard” in case I miss something, or if I am developing something which will be used by someone else which may not know this. I am not very familiar with the library, but if the only required thing is to write the correct types for each native HTML tag, I could definitely take that as soon as I have a little of time. Shouldn’t be very difficult. |
Describe the bug
Looking at these type declarations, I can see some attributes inside the
HTMLAttributes
interface that are commented as 'Standard HTML Attributes' but many of them aren't standard at all.In my particular case I spent a lot of time trying to setup a type with Typescript that used
HTMLAttributes
for a couple of elements (HTMLInputElement
andHTMLTextAreaElement
) which discriminated attributes from one or another depending on a prop value. I was expecting therows
attribute to be present only on theHTMLTextAreaElement
and not in theHTMLInputElement
becauserows
is a native element of atextarea
and not of aninput
. I assumed this and slammed my head onto a wall when I figured out that the attributerows
wasn't being discriminated because it was present as a 'standard' element in the generalHTMLAttributes
interface.Is it intended to be like this because something that I am missing? (I am not very familiar with preact). Every other major framework (including React, Astro and Svelte) don't include this 'standard' attribute.
To Reproduce
I don't think an actual minimal repo isn't necessary in this case, but I have this example of the Typescript Playground which tries to grab the 'rows' attribute from an input element using both the react typings and the preact ones. While the preact ones are resolved, the react ones are not (as I would expect).
Expected behavior
The 'rows' key of the
HTMLAttributes<HTMLInputElement>
should not be resolved (how it happens with the react types).The text was updated successfully, but these errors were encountered: