Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constrain typescript definitions #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 0 additions & 156 deletions dist/index.d.ts

This file was deleted.

27 changes: 0 additions & 27 deletions generate-ts-def.js

This file was deleted.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down Expand Up @@ -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": {
Expand Down
37 changes: 37 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

interface Dictionary<T> {
[index: string]: T,
}

/**
* The minimal featureset the hyperscript implementation should support
*/
declare interface HyperScriptFn<Element, Tag, Attribute = any, Children = Array<Element|string> | string> {
(tag: Tag, children?: Children): Element;
(tag: Tag, attributes: Dictionary<Attribute>, children?: Children): Element;
}

/**
* The actual hyperscript-helper function
* The purpose of hyperscript-helpers is so you can use this function
*/
declare interface HyperScriptHelperFn<Element, Attribute = any, Children = Array<Element|string> | string> {
(selector: string, children?: Children): Element;
(selector: string, attributes: Dictionary<Attribute>, children?: Children): Element;
(attributes: Dictionary<Attribute>, children?: Children): Element;
(children?: Children): Element;
}

/**
* Map of the actual helper functions generated by hh()
*/
declare type HyperScriptHelpers<Element, Attribute = any> = {
[key in (keyof HTMLElementTagNameMap | 'svg')]: HyperScriptHelperFn<Element, Attribute>;
}

export default function hh<
H extends HyperScriptFn<Element, Tag, Attribute>,
Element = ReturnType<H>,
Attribute = any,
Tag = keyof HyperScriptHelpers<Element, Attribute>,
>(h: H): HyperScriptHelpers<Element, Attribute>;