And if TS gets mad you can do this:
declare module 'react' {
interface ButtonHTMLAttributes<T> extends HTMLAttributes<T> {
_variant?: "default" | "outline";
}
}
Typing `data-` attributes in HTMLAttributes via `data-${string}?: string | undefined`. In case anybody wants to contribute that 😉 Currently only works in JSX via <div data-foo="a" />. Not when you try to construct an actual object e.g. props: HTMLAttributes = { 'data-foo': a}
The highest perf issues basically boiled down to unions over large types like React.HTMLProps or HTMLAttributes
This was my POC PR that I broke down into smaller ones (you can search PR's with me as the author and use interface/typescript as they keyword to see examples)
github.com/getsentry/sentry/…
[13/100]
Descobri pelo @edusantosbrito que esses tipos declarados não precisam ficar lá. O ButtonHTMLAtributes faz extends em HTMLAttributes, que já possui o tipo className, e também herda do DomAttributes, onde children já está definido.
#100DiasDeCodigo#100DaysOfCode
Awesome work! One super useful technique that I think deserves to be added here is typing { ...props } by extending the interface with they types from a DOM interface.
ex:
interface MyButton extends HTMLAttributes<HTMLButtonElement>
If you want it to work in every file, use declare global instead.
HTMLAttributes doesn't actually belong to the react module itself, React just overwrites it.
Which would you use to mirror an HTML element in a custom component?
🔹ComponentPropsWithoutRef
🔹ComponentProps
🔹InputHTMLAttributes
🔹JSX.IntrinsicElements
🔹HTMLAttributes
🔹HTMLProps
Yes, very similar. Although I ideally want to make this something most of us never reach for and instead provide the interfaces like HTMLAttributes directly, as shown later in this thread
I found a very subtle utility function for tailwind users to add classNames responsively.
export const withDesktopStyle = (
classNames: HTMLAttributes<HTMLElement>['className']
) => {
return ` ${classNames}`.split(' ').join(' lg:');
};
👀👀