Support SVG elements; Remove extraneous definition

This commit is contained in:
Justin Firth
2017-03-30 18:13:46 -04:00
parent c0083ec134
commit d7218e2fe3
2 changed files with 19 additions and 11 deletions
+15 -4
View File
@@ -59,14 +59,25 @@ h2.cleanup()
/* Polymorphic type tests */
// determine proper HTMLElement type from tagName
let test1: HTMLCanvasElement = h('canvas');
// fall back to Element when in doubt
let fallbackTest = h('canvas#test3');
// determine proper Element type from tagName
let htmlTest1: HTMLCanvasElement = h('canvas');
// allow coercion of decorated tagName to proper type
let test2: HTMLCanvasElement = h<HTMLCanvasElement>('canvas#test2');
let htmlTest2: HTMLCanvasElement = h<HTMLCanvasElement>('canvas#test2');
// if you need it to be an HTMLElement, you must coerce
let htmlTest3 = h<HTMLElement>('canvas#test3');
// support SVG elements
let svgTest1 = h('svg');
// allow coercions on SVG elements
let svgTest2 = h<SVGSVGElement>('svg#test5');
// inline coercion if you were feeling pedantic
// example
h<HTMLDivElement>('div#page',
h<HTMLDivElement>('div#header',
h<HTMLHeadingElement>('h1.classy', 'h', { style: {'background-color': '#22f'} })));
+4 -7
View File
@@ -1,18 +1,15 @@
// Type definitions for hyperscript
// Project: https://github.com/dominictarr/hyperscript
// Definitions by: Mike Linkovich <https://github.com/spacejack>
// Definitions by: Mike Linkovich <https://github.com/spacejack>, Justin Firth <https://github.com/jmfirth/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
declare module 'hyperscript' {
interface HyperScript {
/** Creates a typed HTMLElement */
<T extends keyof HTMLElementTagNameMap>(tagName: T, attrs?: Object, ...children: any[]): HTMLElementTagNameMap[T];
/** Creates a typed HTMLElement via coercion */
<T extends HTMLElement>(tagName: string, attrs?: Object, ...children: any[]): T;
/** Creates an HTMLElement */
<T extends string>(tagName: T, attrs?: Object, ...children: any[]): HTMLElement;
/** Creates an Element */
<T extends keyof ElementTagNameMap>(tagName: T, attrs?: Object, ...children: any[]): ElementTagNameMap[T];
<T extends Element>(tagName: string, attrs?: Object, ...children: any[]): T;
/** Cleans up any event handlers created by this hyperscript context */
cleanup(): void;
/** Creates a new hyperscript context */