You can use JSX.HTMLAttributes<T>
:
interface Props extends JSX.HTMLAttributes<HTMLAnchorElement> {}
This comes in handy when you need extend some element with additional properties like the way we do in React:
export interface Props extends JSX.HTMLAttributes<HTMLInputElement> {
value: Accessor<string>;
onInput: JSX.EventHandler<HTMLInputElement, InputEvent>;
icon?: HTMLImageElement;
label?: HTMLImageElement,
}
const Input: Component<Props> = (props) => {
const [_, ...rest] = splitProps(props, ['icon', 'label']);
const handleInput: JSX.EventHandlerUnion<HTMLInputElement, InputEvent> = (event) => {}
return (
<span class={style.wrapper}>
{props.icon && props.icon}
{props.label && props.label}
<input {...rest} value={props.value()} onInput={handleInput} />
</span>
)
};
And for events you have to ways:
const handleInput: JSX.EventHandler<HTMLInputElement, InputEvent> = (event) => {
console.log(event.currentTarget.value);
};
const handleInput: JSX.EventHandlerUnion<HTMLInputElement, InputEvent> = (event) => {
setValue(event.currentTarget.value);
};
Second one works because it as union:
type JSX.EventHandlerUnion<T, E extends Event> =
| JSX.EventHandler<T, E>
| JSX.BoundEventHandler<T, E>;