Add types of all html properties
oldrich-s opened this issue · 2 comments
I propose to add all the html properties from TypeScript lib into the HyperScript.
Specifically I propose to add:
type MutablePartial<T extends { [x: string]: any }, K extends string> = {
[P in K]?: MutablePartial<T[P], keyof T[P]>;
}
interface Hyperscript {
<K extends keyof ElementTagNameMap>(selector: K, attributes: Attributes & MutablePartial<ElementTagNameMap[K], keyof ElementTagNameMap[K]>, ...children: Children[]): Vnode<any, any>;
...
and to modify
(selector: string, attributes: Attributes, ...children: Children[]): Vnode<any, any>;
into
(selector: string, attributes: Attributes & MutablePartial<HTMLElement, keyof HTMLElement>, ...children: Children[]): Vnode<any, any>;
And then to remove
/** The class name(s) for this virtual element, as a space-separated list. */
className?: string;
from Attributes
as it is already included in HTMLElement
.
This way gives a complete intellisense of all html elements also including all style
properties. Mutable extension must be there to convert readonly style
into mutable one. Partial to make all props optional.
Ok, a little simplification. Hyperscript starts with:
interface Hyperscript {
<K extends keyof ElementTagNameMap>(selector: K, attributes: Attributes | Partial<ElementTagNameMap[K]>, ...children: Children[]): Vnode<any, any>;
and Attributes interface is:
interface Attributes extends Lifecycle<any, any> {
style?: Partial<CSSStyleDeclaration>;
/** The class name(s) for this virtual element, as a space-separated list. */
class?: string;
/** A key to optionally associate with this element. */
key?: string | number;
/** Any other virtual element properties, including attributes and event handlers. */
[property: string]: any;
}
So MutablePartial
is not necessary. Seems to work just fine for me ;)
@czb thanks for taking the time to look into this, and it looks promising. Unfortunately I've been swamped at work lately and haven't had a lot of time to try this out.
If you get tired of waiting you're always free to create a PR for DefinitelyTyped and add the appropriate tests.