Skip to content

Commit 33d992c

Browse files
authored
Merge pull request ctrlplusb#50 from fabianishere/feature/typescript-definitions
Add type definitions for TypeScript
2 parents 3fc83ff + df17fd1 commit 33d992c

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

index.d.ts

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as React from 'react';
2+
3+
/**
4+
* The configuration for an asynchronous component.
5+
*/
6+
export interface Configuration<P> {
7+
resolve: () => Promise<React.Component<P>>;
8+
LoadingComponent?: (props: P) => JSX.Element;
9+
ErrorComponent?: (props: P & { error: Error }) => JSX.Element;
10+
name?: string;
11+
autoResolveES2015Default?: boolean;
12+
env?: 'node' | 'browser';
13+
serverMode?: 'resolve' | 'defer' | 'boundary';
14+
}
15+
16+
/**
17+
* A wrapper to provide the asynchronous component resolving in a React tree.
18+
*/
19+
export class AsyncComponentProvider extends React.Component<ProviderProps> {}
20+
21+
/**
22+
* The properties that the {@link AsyncComponentProvider} accepts.
23+
*/
24+
export interface ProviderProps {
25+
children: JSX.Element[] | JSX.Element;
26+
asyncContext?: Context;
27+
rehydrateState?: object;
28+
}
29+
30+
/**
31+
* This interface defines the asynchronous context uses for the asynchronous resolving
32+
* of components.
33+
*/
34+
export interface Context {
35+
getState: () => object;
36+
}
37+
38+
/**
39+
* Convert the given component to a an asynchronous component.
40+
*
41+
* @param config The configuration to use for the asynchronous component.
42+
*/
43+
export function asyncComponent<T extends React.Component<P>, P>(config: Configuration<P>): React.ComponentClass<P>;
44+
45+
/**
46+
* Create a context for the asynchronous component resolving module.
47+
*/
48+
export function createAsyncContext(): Context;

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"umd",
1111
"commonjs"
1212
],
13+
"typings": "./index.d.ts",
1314
"repository": {
1415
"type": "git",
1516
"url": "https://github.com/ctrlplusb/react-async-component.git"

0 commit comments

Comments
 (0)