Skip to content

Commit bdaa459

Browse files
authored
fix: add missing flow types (#33)
1 parent 2bbb29f commit bdaa459

14 files changed

+1496
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
declare module 'Async.component' {
2+
declare type DataType = {
3+
[key: any]: any
4+
};
5+
6+
declare type LocationType = {
7+
hash: string,
8+
key?: string,
9+
pathname: string,
10+
search: string,
11+
state?: any
12+
};
13+
14+
declare type InitialProps = {
15+
[key: string]: any
16+
};
17+
18+
declare type QueryType = {
19+
[key: string]: string
20+
};
21+
22+
declare type Request = {
23+
url: string,
24+
query: QueryType,
25+
originalUrl: string,
26+
path: string,
27+
[key: string]: any
28+
};
29+
30+
declare type Response = {
31+
status(code: number): void,
32+
redirect(code: number, redirectTo: string): void,
33+
[key: string]: any
34+
};
35+
36+
declare type Assets = {
37+
client: {
38+
css: string,
39+
js: string
40+
}
41+
};
42+
43+
declare type Extractor = {
44+
getStyleTags(): Array<React$Element<'link'>>,
45+
getStyleElements(): Array<React$Element<'link'>>,
46+
getLinkElements(): Array<React$Element<'link'>>
47+
};
48+
49+
declare type Page = {
50+
html: string,
51+
[key: string]: any
52+
};
53+
54+
declare type Context = {
55+
req: Request,
56+
res?: Response,
57+
assets?: Assets,
58+
data?: ?DataType,
59+
filterServerData?: (data: ?DataType) => DataType,
60+
renderPage?: (data: ?DataType) => Promise<Page>,
61+
generateCriticalCSS?: () => string | boolean,
62+
title?: string,
63+
extractor?: ?Extractor,
64+
location?: LocationType,
65+
[key: string]: any
66+
};
67+
68+
declare type AsyncProps = {
69+
[key: string]: any
70+
};
71+
72+
declare type AsyncRouteComponent<T> = React$ComponentType<T> & {
73+
load: () => Promise<React$Node>,
74+
getInitialProps: (context: Context) => Promise<AsyncProps>
75+
};
76+
77+
declare type ComponentType<P> = {
78+
getInitialProps(context: Context): Promise<DataType>
79+
} & $Subtype<React$ComponentType<P>>;
80+
81+
declare type AsyncOptions = {
82+
loader():
83+
| Promise<ComponentType<AsyncProps>>
84+
| Promise<{| +default: ComponentType<AsyncProps> |}>,
85+
LoadableComponent: React$ComponentType<AsyncProps>
86+
};
87+
88+
declare module.exports: {
89+
asyncComponent(opts: AsyncOptions): (props: AsyncProps) => AsyncRouteComponent<AsyncProps>
90+
};
91+
}
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
type Window = {
2+
location: {
3+
hostname: string
4+
}
5+
};
6+
7+
type Reviver = (key: string | number, value: any) => any;
8+
9+
type JSONType = {|
10+
parse(text: string, reviver?: Reviver): { [key: any]: any }
11+
|};
12+
13+
declare module 'Before.component' {
14+
declare var window: Window;
15+
declare var JSON: JSONType;
16+
17+
declare type DataType = {
18+
[key: any]: any
19+
};
20+
21+
declare type LocationType = {
22+
hash: string,
23+
key?: string,
24+
pathname: string,
25+
search: string,
26+
state?: any
27+
};
28+
29+
declare type InitialProps = {
30+
[key: string]: any
31+
};
32+
33+
declare type QueryType = {
34+
[key: string]: string
35+
};
36+
37+
declare type Request = {
38+
url: string,
39+
query: QueryType,
40+
originalUrl: string,
41+
path: string,
42+
[key: string]: any
43+
};
44+
45+
declare type Response = {
46+
status(code: number): void,
47+
redirect(code: number, redirectTo: string): void,
48+
[key: string]: any
49+
};
50+
51+
declare type Assets = {
52+
client: {
53+
css: string,
54+
js: string
55+
}
56+
};
57+
58+
declare type Extractor = {
59+
getStyleTags(): Array<React$Element<'link'>>,
60+
getStyleElements(): Array<React$Element<'link'>>,
61+
getLinkElements(): Array<React$Element<'link'>>
62+
};
63+
64+
declare type Page = {
65+
html: string,
66+
[key: string]: any
67+
};
68+
69+
declare type Context = {
70+
req: Request,
71+
res?: Response,
72+
assets?: Assets,
73+
data?: ?DataType,
74+
filterServerData?: (data: ?DataType) => DataType,
75+
renderPage?: (data: ?DataType) => Promise<Page>,
76+
generateCriticalCSS?: () => string | boolean,
77+
title?: string,
78+
extractor?: ?Extractor,
79+
location: LocationType,
80+
[key: string]: any
81+
};
82+
83+
declare class AsyncComponent extends React$PureComponent<InitialProps> {
84+
static getInitialProps(context: Context): Promise<InitialProps | Error>;
85+
static load(): Promise<React$Node>;
86+
}
87+
88+
declare type FixMeType = Class<AsyncComponent> | typeof AsyncComponent;
89+
90+
declare type AsyncRoute = {
91+
component: FixMeType,
92+
redirectTo?: string,
93+
prefetch?: boolean,
94+
isExact: boolean,
95+
params: { [key: string]: ?string },
96+
url: string,
97+
path: string,
98+
sensitive?: boolean,
99+
strict?: boolean,
100+
exact?: boolean
101+
};
102+
103+
declare type HistoryAction = 'PUSH' | 'REPLACE' | 'POP';
104+
105+
declare type RouterHistory = {
106+
length: number,
107+
location: LocationType,
108+
action: HistoryAction,
109+
listen(callback: (location: LocationType, action: HistoryAction) => void): () => void,
110+
unstable_push(path: string | LocationType, state?: any): void,
111+
push(path: string | LocationType, state?: any): void,
112+
unstable_replace(path: string | LocationType, state?: any): void,
113+
replace(path: string | LocationType, state?: any): void,
114+
go(n: number): void,
115+
goBack(): void,
116+
goForward(): void,
117+
canGo?: (n: number) => boolean,
118+
block(callback: (location: LocationType, action: HistoryAction) => boolean): void,
119+
index?: number,
120+
entries?: Array<LocationType>
121+
};
122+
123+
declare type SwitchRoutesProps = {
124+
+data: ?DataType,
125+
+routes: Array<AsyncRoute>
126+
};
127+
128+
declare type Match = {
129+
params: { [key: string]: ?string },
130+
isExact: boolean,
131+
path: string,
132+
url: string
133+
};
134+
135+
declare type BeforeProps = {|
136+
+data: ?DataType,
137+
+routes: Array<AsyncRoute>,
138+
+req: Request
139+
|};
140+
141+
declare type BeforeState = {
142+
currentLocation: LocationType
143+
};
144+
145+
declare type BeforeAction = {
146+
type: 'update-location' | 'update-props-location',
147+
location: LocationType,
148+
props?: DataType
149+
};
150+
151+
declare type StaticRouterContext = {
152+
url?: string
153+
};
154+
155+
declare type ShouldRenderProps = {
156+
children: React$Element<FixMeType>,
157+
location: LocationType
158+
};
159+
160+
declare type BeforeComponentWithRouterProps = {|
161+
+history: RouterHistory,
162+
+location: LocationType,
163+
+match: Match,
164+
+staticContext?: StaticRouterContext,
165+
+data: ?DataType,
166+
+routes: Array<AsyncRoute>,
167+
+req: Request
168+
|};
169+
170+
declare module.exports: {
171+
Before: (
172+
props: BeforeComponentWithRouterProps
173+
) => React$Element<
174+
Class<
175+
React$Component<{|
176+
children?: Node,
177+
location?: Location
178+
|}>
179+
>
180+
>
181+
};
182+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
declare module 'Document.component' {
2+
import type { Extractor } from '@loadable/server';
3+
4+
declare type Assets = {
5+
client: {
6+
css: string,
7+
js: string
8+
}
9+
};
10+
11+
declare type DataType = {
12+
[key: string]: any
13+
};
14+
15+
declare type Page = {
16+
html: string,
17+
[key: string]: any
18+
};
19+
20+
declare type Context = {
21+
assets: Assets,
22+
data: ?DataType,
23+
renderPage(data: ?DataType): Promise<Page>,
24+
generateCriticalCSS(): string | boolean,
25+
title: string,
26+
extractor: ?Extractor,
27+
[key: string]: any
28+
};
29+
30+
declare type TagMethods = {
31+
toString(): string,
32+
toComponent(): [React$Element<*>] | React$Element<*> | Array<Object>
33+
};
34+
35+
declare type AttributeTagMethods = {
36+
toString(): string,
37+
toComponent(): { [key: string]: any }
38+
};
39+
40+
declare type Helmet = {
41+
base: TagMethods,
42+
bodyAttributes: AttributeTagMethods,
43+
htmlAttributes: AttributeTagMethods,
44+
link: TagMethods,
45+
meta: TagMethods,
46+
noscript: TagMethods,
47+
script: TagMethods,
48+
style: TagMethods,
49+
title: TagMethods
50+
};
51+
52+
declare type ErrorProps = {
53+
error: Error
54+
};
55+
56+
declare type ExtraTag = {
57+
name: string,
58+
tag: string,
59+
content: string,
60+
attribs?: {
61+
[key: string]: string
62+
}
63+
};
64+
65+
declare type DocumentInitialProps = {
66+
assets: Assets,
67+
criticalCSS: boolean | string,
68+
data: DataType,
69+
renderPage?: (data: { [key: string]: any }) => Promise<any>,
70+
generateCriticalCSS?: () => string | boolean,
71+
title: string,
72+
extractor: ?Extractor,
73+
helmet: Helmet,
74+
error: Error,
75+
errorComponent?: React$ComponentType<ErrorProps>,
76+
filterServerData?: (data: DataType) => DataType,
77+
extraHeadTags?: Array<ExtraTag>,
78+
extraBodyTags?: Array<ExtraTag>,
79+
[key: string]: any
80+
};
81+
82+
declare type DocumentGetInitialProps = {
83+
criticalCSS: boolean | string,
84+
assets: Assets,
85+
data: DataType,
86+
extractor: Extractor,
87+
html: string,
88+
[key: string]: any
89+
};
90+
91+
declare type DocumentComponent = {
92+
getInitialProps(context: Context): Promise<DocumentGetInitialProps>
93+
} & $Subtype<React$ComponentType<DocumentInitialProps>>;
94+
95+
declare module.exports: {
96+
DocumentComponent: DocumentComponent,
97+
Root: (props: { jsx: ?string }) => React$Element<'div'>,
98+
Data: (arg: { data: DataType }) => React$Element<'script'>
99+
};
100+
}

0 commit comments

Comments
 (0)