Skip to content

Commit b1a1956

Browse files
pmkroekermarvinhagemeister
authored andcommittedMay 8, 2019
Add types to compat (preactjs#1609)
* Add types to `compat` * Updated createElement typing * Fix toArray and PureComponent * Fix count -> number * Map and for each abstraction * unstable_batchedUpdates callback (arg?: any) * Remove spaces after function names * Fix forwardRef * Remove `shouldComponentUpdate` dupe from PureComponent * Removed duplicated entries * Re-use preact defs * VNode from internal -> preact.VNode * createPortal container add | Element * PreactElement -> Element * Remove namespace * Add default export.
1 parent 4aabebb commit b1a1956

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
 

‎compat/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"module": "dist/compat.module.js",
99
"umd:main": "dist/compat.umd.js",
1010
"source": "src/index.js",
11+
"types": "src/index.d.ts",
1112
"license": "MIT",
1213
"mangle": {
1314
"regex": "^_"

‎compat/src/index.d.ts

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import * as _hooks from '../../hooks';
2+
import * as preact from '../../src';
3+
import { ForwardFn } from './internal';
4+
5+
export * from '../../hooks';
6+
export import Component = preact.Component;
7+
export import createContext = preact.createContext;
8+
export import createRef = preact.createRef;
9+
export import Fragment = preact.Fragment;
10+
export import createElement = preact.createElement
11+
export import cloneElement = preact.cloneElement
12+
13+
export declare const version: string;
14+
15+
export declare function createPortal(vnode: preact.VNode, container: Element | Element): preact.VNode<any>;
16+
17+
export declare function render(vnode: preact.VNode<any>, parent: Element, callback?: () => void): Component | null;
18+
19+
export declare function hydrate(vnode: preact.VNode<any>, parent: Element, callback?: () => void): Component | null;
20+
21+
export declare function unmountComponentAtNode(container: Element | Document | ShadowRoot | DocumentFragment): boolean;
22+
23+
export declare function createFactory(type: preact.VNode["type"]): preact.VNode<{}>;
24+
25+
export declare function isValidElement(element: any): boolean;
26+
27+
export declare function findDOMNode(component: preact.Component): Element | null;
28+
29+
export declare interface PureComponent<P = {}, S = {}> extends preact.Component {
30+
isPureReactComponenet: boolean;
31+
}
32+
33+
export declare function memo<P = {}>(component: preact.FunctionalComponent<P>, comparer?: (prev: P, next: P) => boolean): preact.FunctionComponent<P>;
34+
35+
export declare function forwardRef<P = {}>(fn: ForwardFn<P, any>): preact.FunctionalComponent<P>;
36+
37+
export declare function unstable_batchedUpdates(callback: (arg?: any) => void, arg?: any): void;
38+
39+
40+
export declare interface Children {
41+
map<T extends preact.ComponentChild, R>(children: T | T[], fn: (child: T, i: number, array: T[]) => R): R[];
42+
forEach<T extends preact.ComponentChild>(children: T | T[], fn: (child: T, i: number, array: T[]) => void): void;
43+
count: (children: preact.ComponentChildren) => number;
44+
only: (children: preact.ComponentChildren) => preact.ComponentChild;
45+
toArray: (children: preact.ComponentChildren) => preact.VNode<{}>[];
46+
}
47+
48+
declare const _default: {
49+
hooks: typeof _hooks,
50+
Component: Component,
51+
createContext: typeof createContext,
52+
createRef: typeof createRef,
53+
Fragment: typeof Fragment,
54+
createElement: typeof createElement,
55+
cloneElement: typeof cloneElement,
56+
version: typeof version,
57+
createPortal: typeof createPortal,
58+
render: typeof render,
59+
hydrate: typeof render,
60+
unmountComponentAtNode: typeof unmountComponentAtNode,
61+
createFactory: typeof createFactory,
62+
isValidElement: typeof isValidElement,
63+
findDOMNode: typeof findDOMNode,
64+
PureComponent: PureComponent,
65+
memo: typeof memo,
66+
forwardRef: typeof forwardRef,
67+
unstable_batchedUpdates: typeof unstable_batchedUpdates,
68+
Children: Children,
69+
};
70+
71+
export default _default;

0 commit comments

Comments
 (0)
Please sign in to comment.