From d7218e2fe3345e43c1bb90649abec084c71a8592 Mon Sep 17 00:00:00 2001 From: Justin Firth Date: Thu, 30 Mar 2017 18:13:46 -0400 Subject: [PATCH] Support SVG elements; Remove extraneous definition --- types/hyperscript/hyperscript-tests.ts | 19 +++++++++++++++---- types/hyperscript/index.d.ts | 11 ++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/types/hyperscript/hyperscript-tests.ts b/types/hyperscript/hyperscript-tests.ts index 02ea158977..687a2591c1 100644 --- a/types/hyperscript/hyperscript-tests.ts +++ b/types/hyperscript/hyperscript-tests.ts @@ -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('canvas#test2'); +let htmlTest2: HTMLCanvasElement = h('canvas#test2'); + +// if you need it to be an HTMLElement, you must coerce +let htmlTest3 = h('canvas#test3'); + +// support SVG elements +let svgTest1 = h('svg'); + +// allow coercions on SVG elements +let svgTest2 = h('svg#test5'); // inline coercion if you were feeling pedantic -// example h('div#page', h('div#header', h('h1.classy', 'h', { style: {'background-color': '#22f'} }))); \ No newline at end of file diff --git a/types/hyperscript/index.d.ts b/types/hyperscript/index.d.ts index b4384ba302..cec67e56ab 100644 --- a/types/hyperscript/index.d.ts +++ b/types/hyperscript/index.d.ts @@ -1,18 +1,15 @@ // Type definitions for hyperscript // Project: https://github.com/dominictarr/hyperscript -// Definitions by: Mike Linkovich +// Definitions by: Mike Linkovich , Justin Firth // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 declare module 'hyperscript' { interface HyperScript { - /** Creates a typed HTMLElement */ - (tagName: T, attrs?: Object, ...children: any[]): HTMLElementTagNameMap[T]; - /** Creates a typed HTMLElement via coercion */ - (tagName: string, attrs?: Object, ...children: any[]): T; - /** Creates an HTMLElement */ - (tagName: T, attrs?: Object, ...children: any[]): HTMLElement; + /** Creates an Element */ + (tagName: T, attrs?: Object, ...children: any[]): ElementTagNameMap[T]; + (tagName: string, attrs?: Object, ...children: any[]): T; /** Cleans up any event handlers created by this hyperscript context */ cleanup(): void; /** Creates a new hyperscript context */