forked from andeee/react-hyperscript-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-ts-def.js
28 lines (23 loc) · 1.4 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
import fs from 'fs';
import { TAG_NAMES } from './lib/tag-names.js';
const typings =
`import { Component, HTMLAttributes, Props, ReactNode, ReactElement, ComponentClass, StatelessComponent } from 'react';
declare type ReactComponent<P> = string | ComponentClass<P> | StatelessComponent<P>;
export function hh(component: ReactComponent<any>): (selector?: any, properties?: any, ...children: ReactNode[]) => ReactElement<any>;
export function h(component: ReactComponent<any>, ...children: ReactNode[]): ReactElement<any>;
export function h(component: ReactComponent<any>, selector: string, ...children: ReactNode[]): ReactElement<any>;
export function h<P>(component: ReactComponent<P>, selector: string, properties: P & Props<any>, ...children: ReactNode[]): ReactElement<any>;
export function h<P>(component: ReactComponent<P>, properties: P & Props<any>, ...children: ReactNode[]): ReactElement<any>;
${
TAG_NAMES.reduce((accum, tag) => `${accum}
export function ${tag}(...children: ReactNode[]): ReactElement<any>;
export function ${tag}(selector: string, ...children: ReactNode[]): ReactElement<any>;
export function ${tag}(selector: string, properties: HTMLAttributes<any>, ...children: ReactNode[]): ReactElement<any>;
export function ${tag}(properties: HTMLAttributes<any>, ...children: ReactNode[]): ReactElement<any>;`
, ``)
}`;
fs.writeFile('./lib/index.d.ts', typings, (err) => {
if (err) {
throw err;
}
});