This repository was archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js.flow
37 lines (32 loc) · 1.62 KB
/
index.js.flow
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
29
30
31
32
33
34
35
36
37
// @flow
import * as React from 'react';
export type ClassComponent<Props, State> =
Class<React.Component<Props, State>>;
export type ClassComponentWithDefaultProps<DefaultProps, Props, State> =
ClassComponent<Props, State> & {defaultProps: DefaultProps};
export type ComponentWithDefaultProps<DefaultProps, Props> =
React.ComponentType<Props> & {defaultProps: DefaultProps};
/**
* Here is a generic type for HOCs:
*
* It takes two type parameters: RequiredProps and ProvidedProps
*
* RequiredProps: The final wrapped component will need RequiredProps, in addition to its own props
* ProvidedProps: The final wrapped component will not need ProvidedProps, because the HOC will provide them to the inner component
*/
export type HigherOrderComponent<RequiredProps, ProvidedProps> =
& (
<Props, DefaultProps>(component: ComponentWithDefaultProps<DefaultProps, ProvidedProps & Props>) =>
React.ComponentType<
// Merge in RequiredProps
& RequiredProps
// Props, with diffed-out default props. Make sure to merge with ProvidedProps to work with
// $Diff constraints in nested HoCs.
& $Diff<ProvidedProps & Props, DefaultProps & ProvidedProps>
// Force props to be in the shape of all potential props (effectively allows properly-typed
// overrides of DefaultProps)
& $Shape<RequiredProps & DefaultProps & Props>
>
)
& (<Props>(component: React.StatelessFunctionalComponent<ProvidedProps & Props>) => React.ComponentType<RequiredProps & Props>)
& (<Props>(component: React.ComponentType<ProvidedProps & Props>) => React.ComponentType<RequiredProps & Props>)