forked from Jador/react-hyperscript-helpers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate-ts-def.js
40 lines (35 loc) · 1.91 KB
/
generate-ts-def.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import fs from 'fs';
import { TAG_NAMES } from './lib/tag-names.js';
const typings =
`import { Component, HTMLAttributes, Props, ReactChild, ReactElement } from 'react';
declare interface ClassComponent<P> {
new(...args): Component<P, any>;
}
declare interface StatelessComponent<P> {
(props: P): ReactElement;
}
declare type Children = ReactChild | ReactChild[];
declare type ReactComponent<P> = ClassComponent<P> | StatelessComponent<P>;
export function hh(tag: string): (selector?: any, properties?: any, children?: Children) => ReactElement;
export function hh(component: ReactComponent<any>): (selector?: any, properties?: any, children?: Children) => ReactElement;
export function h(tag: string, children?: Children): ReactElement;
export function h(tag: string, selector: string, children?: Children): ReactElement;
export function h(tag: string, selector: string, properties: HTMLAttributes, children?: Children): ReactElement;
export function h(tag: string, properties: HTMLAttributes, children?: Children): ReactElement;
export function h(component: ReactComponent<any>, children?: Children): ReactElement;
export function h(component: ReactComponent<any>, selector: string, children?: Children): ReactElement;
export function h<P>(component: ReactComponent<P>, selector: string, properties: P & Props<any>, children?: Children): ReactElement;
export function h<P>(component: ReactComponent<P>, properties: P & Props<any>, children?: Children): ReactElement;
${
TAG_NAMES.reduce((accum, tag) => `${accum}
export function ${tag}(children?: Children): ReactElement;
export function ${tag}(selector: string, children?: Children): ReactElement;
export function ${tag}(selector: string, properties: HTMLAttributes, children?: Children): ReactElement;
export function ${tag}(properties: HTMLAttributes, children?: Children): ReactElement;`
, ``)
}`;
fs.writeFile('./lib/index.d.ts', typings, (err) => {
if (err) {
throw err;
}
});