Skip to content

Commit 9a0b147

Browse files
Merge pull request #201 from rikuba/add-typings
Add typings
2 parents f98dbfa + caeaa0a commit 9a0b147

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

cjs/index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import hyper from "..";
2+
export * from '..';
3+
export default hyper;

esm/index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import hyper from "..";
2+
export * from '..';
3+
export default hyper;

index.d.ts

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
type TemplateFunction<T> = (template: TemplateStringsArray, ...values: any[]) => T;
2+
export type BoundTemplateFunction<T extends Element> = TemplateFunction<T>;
3+
export type WiredTemplateFunction = TemplateFunction<any>;
4+
5+
export declare class Component<T = {}> {
6+
handleEvent(e: Event): void;
7+
html: WiredTemplateFunction;
8+
svg: WiredTemplateFunction;
9+
state: T;
10+
readonly defaultState: T;
11+
setState(state: Partial<T> | ((this: this, state: T) => Partial<T>)): void;
12+
}
13+
14+
export declare function bind<T extends Element>(element: T): BoundTemplateFunction<T>;
15+
16+
export declare function define(intent: string, callback: Function): void;
17+
18+
export declare function wire(identity?: object | null, type?: 'html' | 'svg'): WiredTemplateFunction;
19+
export declare function wire(identity?: object | null, type_id?: string): WiredTemplateFunction;
20+
21+
export declare const hyper: {
22+
Component: typeof Component;
23+
bind: typeof bind;
24+
define: typeof define;
25+
hyper: typeof hyper;
26+
wire: typeof wire;
27+
28+
// hyper(null, 'html')`HTML`
29+
(identity: null | undefined, type?: 'html' | 'svg'): WiredTemplateFunction;
30+
31+
// hyper('html')`HTML`
32+
(type: 'html' | 'svg'): WiredTemplateFunction;
33+
34+
// hyper(element)`HTML`
35+
<T extends Element>(element: T): BoundTemplateFunction<T>;
36+
37+
// hyper`HTML`
38+
(template: TemplateStringsArray, ...values: any[]): any;
39+
40+
// hyper(obj, 'html:id')`HTML`
41+
// hyper(obj)`HTML`
42+
(identity: object, type?: 'html' | 'svg'): WiredTemplateFunction;
43+
(identity: object, type_id?: string): WiredTemplateFunction;
44+
45+
// hyper()`HTML`
46+
(): WiredTemplateFunction;
47+
};
48+
49+
export default hyper;

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"browser": "min.js",
77
"main": "cjs/index.js",
88
"module": "esm/index.js",
9+
"types": "index.d.ts",
910
"scripts": {
1011
"add-domdiff": "echo '/* AUTOMATICALLY IMPORTED, DO NOT MODIFY */' > esm/shared/domdiff.js && cat node_modules/domdiff/esm/index.js >> esm/shared/domdiff.js",
1112
"build": "npm run cjs && npm run max && npm run min && npm run ie && npm test && npm run size",

umd.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import hyper from '.';
2+
export * from '.';
3+
export default hyper;

0 commit comments

Comments
 (0)