Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Add types of all html properties #24

Open
oldrich-s opened this issue Jul 14, 2017 · 2 comments
Open

Add types of all html properties #24

oldrich-s opened this issue Jul 14, 2017 · 2 comments

Comments

@oldrich-s
Copy link

oldrich-s commented Jul 14, 2017

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.

@oldrich-s
Copy link
Author

oldrich-s commented Jul 15, 2017

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 ;)

@spacejack
Copy link
Collaborator

spacejack commented Jul 26, 2017

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants