From c5cb428dcc1e0d6cee776af3b86e138b2ff27b5b Mon Sep 17 00:00:00 2001 From: Erik van Velzen Date: Sun, 17 Jun 2018 19:57:52 +0200 Subject: [PATCH] Constrain typescript definitions --- dist/index.d.ts | 156 --------------------------------------------- generate-ts-def.js | 27 -------- package.json | 5 +- src/index.d.ts | 37 +++++++++++ 4 files changed, 39 insertions(+), 186 deletions(-) delete mode 100644 dist/index.d.ts delete mode 100644 generate-ts-def.js create mode 100644 src/index.d.ts diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index 7c622b6..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,156 +0,0 @@ -declare interface HyperScriptHelperFn { - (selector?: any, properties?: any, children?: any): any; -} - -declare type HyperScriptHelpers = { - a: HyperScriptHelperFn; - abbr: HyperScriptHelperFn; - acronym: HyperScriptHelperFn; - address: HyperScriptHelperFn; - applet: HyperScriptHelperFn; - area: HyperScriptHelperFn; - article: HyperScriptHelperFn; - aside: HyperScriptHelperFn; - audio: HyperScriptHelperFn; - b: HyperScriptHelperFn; - base: HyperScriptHelperFn; - basefont: HyperScriptHelperFn; - bdi: HyperScriptHelperFn; - bdo: HyperScriptHelperFn; - bgsound: HyperScriptHelperFn; - big: HyperScriptHelperFn; - blink: HyperScriptHelperFn; - blockquote: HyperScriptHelperFn; - body: HyperScriptHelperFn; - br: HyperScriptHelperFn; - button: HyperScriptHelperFn; - canvas: HyperScriptHelperFn; - caption: HyperScriptHelperFn; - center: HyperScriptHelperFn; - cite: HyperScriptHelperFn; - code: HyperScriptHelperFn; - col: HyperScriptHelperFn; - colgroup: HyperScriptHelperFn; - command: HyperScriptHelperFn; - content: HyperScriptHelperFn; - data: HyperScriptHelperFn; - datalist: HyperScriptHelperFn; - dd: HyperScriptHelperFn; - del: HyperScriptHelperFn; - details: HyperScriptHelperFn; - dfn: HyperScriptHelperFn; - dialog: HyperScriptHelperFn; - dir: HyperScriptHelperFn; - div: HyperScriptHelperFn; - dl: HyperScriptHelperFn; - dt: HyperScriptHelperFn; - element: HyperScriptHelperFn; - em: HyperScriptHelperFn; - embed: HyperScriptHelperFn; - fieldset: HyperScriptHelperFn; - figcaption: HyperScriptHelperFn; - figure: HyperScriptHelperFn; - font: HyperScriptHelperFn; - footer: HyperScriptHelperFn; - form: HyperScriptHelperFn; - frame: HyperScriptHelperFn; - frameset: HyperScriptHelperFn; - h1: HyperScriptHelperFn; - h2: HyperScriptHelperFn; - h3: HyperScriptHelperFn; - h4: HyperScriptHelperFn; - h5: HyperScriptHelperFn; - h6: HyperScriptHelperFn; - head: HyperScriptHelperFn; - header: HyperScriptHelperFn; - hgroup: HyperScriptHelperFn; - hr: HyperScriptHelperFn; - html: HyperScriptHelperFn; - i: HyperScriptHelperFn; - iframe: HyperScriptHelperFn; - image: HyperScriptHelperFn; - img: HyperScriptHelperFn; - input: HyperScriptHelperFn; - ins: HyperScriptHelperFn; - isindex: HyperScriptHelperFn; - kbd: HyperScriptHelperFn; - keygen: HyperScriptHelperFn; - label: HyperScriptHelperFn; - legend: HyperScriptHelperFn; - li: HyperScriptHelperFn; - link: HyperScriptHelperFn; - listing: HyperScriptHelperFn; - main: HyperScriptHelperFn; - map: HyperScriptHelperFn; - mark: HyperScriptHelperFn; - marquee: HyperScriptHelperFn; - math: HyperScriptHelperFn; - menu: HyperScriptHelperFn; - menuitem: HyperScriptHelperFn; - meta: HyperScriptHelperFn; - meter: HyperScriptHelperFn; - multicol: HyperScriptHelperFn; - nav: HyperScriptHelperFn; - nextid: HyperScriptHelperFn; - nobr: HyperScriptHelperFn; - noembed: HyperScriptHelperFn; - noframes: HyperScriptHelperFn; - noscript: HyperScriptHelperFn; - object: HyperScriptHelperFn; - ol: HyperScriptHelperFn; - optgroup: HyperScriptHelperFn; - option: HyperScriptHelperFn; - output: HyperScriptHelperFn; - p: HyperScriptHelperFn; - param: HyperScriptHelperFn; - picture: HyperScriptHelperFn; - plaintext: HyperScriptHelperFn; - pre: HyperScriptHelperFn; - progress: HyperScriptHelperFn; - q: HyperScriptHelperFn; - rb: HyperScriptHelperFn; - rbc: HyperScriptHelperFn; - rp: HyperScriptHelperFn; - rt: HyperScriptHelperFn; - rtc: HyperScriptHelperFn; - ruby: HyperScriptHelperFn; - s: HyperScriptHelperFn; - samp: HyperScriptHelperFn; - script: HyperScriptHelperFn; - section: HyperScriptHelperFn; - select: HyperScriptHelperFn; - shadow: HyperScriptHelperFn; - slot: HyperScriptHelperFn; - small: HyperScriptHelperFn; - source: HyperScriptHelperFn; - spacer: HyperScriptHelperFn; - span: HyperScriptHelperFn; - strike: HyperScriptHelperFn; - strong: HyperScriptHelperFn; - style: HyperScriptHelperFn; - sub: HyperScriptHelperFn; - summary: HyperScriptHelperFn; - sup: HyperScriptHelperFn; - svg: HyperScriptHelperFn; - table: HyperScriptHelperFn; - tbody: HyperScriptHelperFn; - td: HyperScriptHelperFn; - template: HyperScriptHelperFn; - textarea: HyperScriptHelperFn; - tfoot: HyperScriptHelperFn; - th: HyperScriptHelperFn; - thead: HyperScriptHelperFn; - time: HyperScriptHelperFn; - title: HyperScriptHelperFn; - tr: HyperScriptHelperFn; - track: HyperScriptHelperFn; - tt: HyperScriptHelperFn; - u: HyperScriptHelperFn; - ul: HyperScriptHelperFn; - var: HyperScriptHelperFn; - video: HyperScriptHelperFn; - wbr: HyperScriptHelperFn; - xmp: HyperScriptHelperFn; -} - -export default function hh(h: Function): HyperScriptHelpers; diff --git a/generate-ts-def.js b/generate-ts-def.js deleted file mode 100644 index df42b0b..0000000 --- a/generate-ts-def.js +++ /dev/null @@ -1,27 +0,0 @@ -import fs from 'fs'; -import tagNames from 'html-tag-names'; -import hh from './src/index'; - -const start = -`declare interface HyperScriptHelperFn { - (selector?: any, properties?: any, children?: any): any; -} - -declare type HyperScriptHelpers = {`; - -const middle = tagNames.reduce((accum, tag) => { - return accum + ` - ${tag}: HyperScriptHelperFn;`; -}, ``); - -const end = ` -} - -export default function hh(h: Function): HyperScriptHelpers; -`; - -fs.writeFile('./dist/index.d.ts', start + middle + end, (err) => { - if (err) { - throw err; - } -}); diff --git a/package.json b/package.json index aadaabb..7a965d4 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "3.0.3", "description": "Terse syntax for hyperscript", "main": "dist/index.js", - "typings": "dist/index.d.ts", + "typings": "src/index.d.ts", "config": { "commitizen": { "path": "node_modules/rb-conventional-changelog/" @@ -32,8 +32,7 @@ "lint": "./node_modules/.bin/eslint src/", "test": "npm run lint && mocha", "start": "./node_modules/.bin/babel src --out-dir=dist", - "ts-def": "./node_modules/.bin/babel-node ./generate-ts-def.js", - "prestart": "npm install && npm run ts-def", + "prestart": "npm install", "commit": "./node_modules/.bin/git-cz" }, "repository": { diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..e84ed64 --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1,37 @@ + +interface Dictionary { + [index: string]: T, +} + +/** + * The minimal featureset the hyperscript implementation should support + */ +declare interface HyperScriptFn | string> { + (tag: Tag, children?: Children): Element; + (tag: Tag, attributes: Dictionary, children?: Children): Element; +} + +/** + * The actual hyperscript-helper function + * The purpose of hyperscript-helpers is so you can use this function + */ +declare interface HyperScriptHelperFn | string> { + (selector: string, children?: Children): Element; + (selector: string, attributes: Dictionary, children?: Children): Element; + (attributes: Dictionary, children?: Children): Element; + (children?: Children): Element; +} + +/** + * Map of the actual helper functions generated by hh() + */ +declare type HyperScriptHelpers = { + [key in (keyof HTMLElementTagNameMap | 'svg')]: HyperScriptHelperFn; +} + +export default function hh< + H extends HyperScriptFn, + Element = ReturnType, + Attribute = any, + Tag = keyof HyperScriptHelpers, +>(h: H): HyperScriptHelpers;