Skip to content

Commit

Permalink
fix: add missing flow types (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
crash7 committed Oct 7, 2019
1 parent 2bbb29f commit bdaa459
Show file tree
Hide file tree
Showing 14 changed files with 1,496 additions and 0 deletions.
91 changes: 91 additions & 0 deletions packages/client/flow-typed/asyncComponent_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
declare module 'Async.component' {
declare type DataType = {
[key: any]: any
};

declare type LocationType = {
hash: string,
key?: string,
pathname: string,
search: string,
state?: any
};

declare type InitialProps = {
[key: string]: any
};

declare type QueryType = {
[key: string]: string
};

declare type Request = {
url: string,
query: QueryType,
originalUrl: string,
path: string,
[key: string]: any
};

declare type Response = {
status(code: number): void,
redirect(code: number, redirectTo: string): void,
[key: string]: any
};

declare type Assets = {
client: {
css: string,
js: string
}
};

declare type Extractor = {
getStyleTags(): Array<React$Element<'link'>>,
getStyleElements(): Array<React$Element<'link'>>,
getLinkElements(): Array<React$Element<'link'>>
};

declare type Page = {
html: string,
[key: string]: any
};

declare type Context = {
req: Request,
res?: Response,
assets?: Assets,
data?: ?DataType,
filterServerData?: (data: ?DataType) => DataType,
renderPage?: (data: ?DataType) => Promise<Page>,
generateCriticalCSS?: () => string | boolean,
title?: string,
extractor?: ?Extractor,
location?: LocationType,
[key: string]: any
};

declare type AsyncProps = {
[key: string]: any
};

declare type AsyncRouteComponent<T> = React$ComponentType<T> & {
load: () => Promise<React$Node>,
getInitialProps: (context: Context) => Promise<AsyncProps>
};

declare type ComponentType<P> = {
getInitialProps(context: Context): Promise<DataType>
} & $Subtype<React$ComponentType<P>>;

declare type AsyncOptions = {
loader():
| Promise<ComponentType<AsyncProps>>
| Promise<{| +default: ComponentType<AsyncProps> |}>,
LoadableComponent: React$ComponentType<AsyncProps>
};

declare module.exports: {
asyncComponent(opts: AsyncOptions): (props: AsyncProps) => AsyncRouteComponent<AsyncProps>
};
}
182 changes: 182 additions & 0 deletions packages/client/flow-typed/beforeComponent_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
type Window = {
location: {
hostname: string
}
};

type Reviver = (key: string | number, value: any) => any;

type JSONType = {|
parse(text: string, reviver?: Reviver): { [key: any]: any }
|};

declare module 'Before.component' {
declare var window: Window;
declare var JSON: JSONType;

declare type DataType = {
[key: any]: any
};

declare type LocationType = {
hash: string,
key?: string,
pathname: string,
search: string,
state?: any
};

declare type InitialProps = {
[key: string]: any
};

declare type QueryType = {
[key: string]: string
};

declare type Request = {
url: string,
query: QueryType,
originalUrl: string,
path: string,
[key: string]: any
};

declare type Response = {
status(code: number): void,
redirect(code: number, redirectTo: string): void,
[key: string]: any
};

declare type Assets = {
client: {
css: string,
js: string
}
};

declare type Extractor = {
getStyleTags(): Array<React$Element<'link'>>,
getStyleElements(): Array<React$Element<'link'>>,
getLinkElements(): Array<React$Element<'link'>>
};

declare type Page = {
html: string,
[key: string]: any
};

declare type Context = {
req: Request,
res?: Response,
assets?: Assets,
data?: ?DataType,
filterServerData?: (data: ?DataType) => DataType,
renderPage?: (data: ?DataType) => Promise<Page>,
generateCriticalCSS?: () => string | boolean,
title?: string,
extractor?: ?Extractor,
location: LocationType,
[key: string]: any
};

declare class AsyncComponent extends React$PureComponent<InitialProps> {
static getInitialProps(context: Context): Promise<InitialProps | Error>;
static load(): Promise<React$Node>;
}

declare type FixMeType = Class<AsyncComponent> | typeof AsyncComponent;

declare type AsyncRoute = {
component: FixMeType,
redirectTo?: string,
prefetch?: boolean,
isExact: boolean,
params: { [key: string]: ?string },
url: string,
path: string,
sensitive?: boolean,
strict?: boolean,
exact?: boolean
};

declare type HistoryAction = 'PUSH' | 'REPLACE' | 'POP';

declare type RouterHistory = {
length: number,
location: LocationType,
action: HistoryAction,
listen(callback: (location: LocationType, action: HistoryAction) => void): () => void,
unstable_push(path: string | LocationType, state?: any): void,
push(path: string | LocationType, state?: any): void,
unstable_replace(path: string | LocationType, state?: any): void,
replace(path: string | LocationType, state?: any): void,
go(n: number): void,
goBack(): void,
goForward(): void,
canGo?: (n: number) => boolean,
block(callback: (location: LocationType, action: HistoryAction) => boolean): void,
index?: number,
entries?: Array<LocationType>
};

declare type SwitchRoutesProps = {
+data: ?DataType,
+routes: Array<AsyncRoute>
};

declare type Match = {
params: { [key: string]: ?string },
isExact: boolean,
path: string,
url: string
};

declare type BeforeProps = {|
+data: ?DataType,
+routes: Array<AsyncRoute>,
+req: Request
|};

declare type BeforeState = {
currentLocation: LocationType
};

declare type BeforeAction = {
type: 'update-location' | 'update-props-location',
location: LocationType,
props?: DataType
};

declare type StaticRouterContext = {
url?: string
};

declare type ShouldRenderProps = {
children: React$Element<FixMeType>,
location: LocationType
};

declare type BeforeComponentWithRouterProps = {|
+history: RouterHistory,
+location: LocationType,
+match: Match,
+staticContext?: StaticRouterContext,
+data: ?DataType,
+routes: Array<AsyncRoute>,
+req: Request
|};

declare module.exports: {
Before: (
props: BeforeComponentWithRouterProps
) => React$Element<
Class<
React$Component<{|
children?: Node,
location?: Location
|}>
>
>
};
}
100 changes: 100 additions & 0 deletions packages/client/flow-typed/documentComponent_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
declare module 'Document.component' {
import type { Extractor } from '@loadable/server';

declare type Assets = {
client: {
css: string,
js: string
}
};

declare type DataType = {
[key: string]: any
};

declare type Page = {
html: string,
[key: string]: any
};

declare type Context = {
assets: Assets,
data: ?DataType,
renderPage(data: ?DataType): Promise<Page>,
generateCriticalCSS(): string | boolean,
title: string,
extractor: ?Extractor,
[key: string]: any
};

declare type TagMethods = {
toString(): string,
toComponent(): [React$Element<*>] | React$Element<*> | Array<Object>
};

declare type AttributeTagMethods = {
toString(): string,
toComponent(): { [key: string]: any }
};

declare type Helmet = {
base: TagMethods,
bodyAttributes: AttributeTagMethods,
htmlAttributes: AttributeTagMethods,
link: TagMethods,
meta: TagMethods,
noscript: TagMethods,
script: TagMethods,
style: TagMethods,
title: TagMethods
};

declare type ErrorProps = {
error: Error
};

declare type ExtraTag = {
name: string,
tag: string,
content: string,
attribs?: {
[key: string]: string
}
};

declare type DocumentInitialProps = {
assets: Assets,
criticalCSS: boolean | string,
data: DataType,
renderPage?: (data: { [key: string]: any }) => Promise<any>,
generateCriticalCSS?: () => string | boolean,
title: string,
extractor: ?Extractor,
helmet: Helmet,
error: Error,
errorComponent?: React$ComponentType<ErrorProps>,
filterServerData?: (data: DataType) => DataType,
extraHeadTags?: Array<ExtraTag>,
extraBodyTags?: Array<ExtraTag>,
[key: string]: any
};

declare type DocumentGetInitialProps = {
criticalCSS: boolean | string,
assets: Assets,
data: DataType,
extractor: Extractor,
html: string,
[key: string]: any
};

declare type DocumentComponent = {
getInitialProps(context: Context): Promise<DocumentGetInitialProps>
} & $Subtype<React$ComponentType<DocumentInitialProps>>;

declare module.exports: {
DocumentComponent: DocumentComponent,
Root: (props: { jsx: ?string }) => React$Element<'div'>,
Data: (arg: { data: DataType }) => React$Element<'script'>
};
}
Loading

0 comments on commit bdaa459

Please sign in to comment.