///
declare module "recompose" {
import type * as PropTypes from "prop-types";
import * as React from "react";
import { ComponentClass, ComponentType as Component, FunctionComponent } from "react";
type mapper = (input: TInner) => TOutter;
type predicate = mapper;
type predicateDiff = (current: T, next: T) => boolean;
// Diff / Omit taken from https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html
type Omit = Pick>;
interface Observer {
next(props: T): void;
complete(): void;
}
interface Subscription {
unsubscribe(): void;
}
interface Subscribable {
subscribe(observer: Observer): Subscription;
}
interface ComponentEnhancer {
(component: Component): ComponentClass;
}
// Injects props and removes them from the prop requirements.
// Will not pass through the injected props if they are passed in during
// render. Also adds new prop requirements from TNeedsProps.
export interface InferableComponentEnhancerWithProps {
(
component: Component
,
): React.ComponentClass & TNeedsProps>;
}
// Injects props and removes them from the prop requirements.
// Will not pass through the injected props if they are passed in during
// render.
export type InferableComponentEnhancer = InferableComponentEnhancerWithProps;
// Injects default props and makes them optional. Will still pass through
// the injected props if they are passed in during render.
export type DefaultingInferableComponentEnhancer = InferableComponentEnhancerWithProps<
TInjectedProps,
Partial
>;
// Higher-order components: https://github.com/acdlite/recompose/blob/master/docs/API.md#higher-order-components
// mapProps: https://github.com/acdlite/recompose/blob/master/docs/API.md#mapprops
export function mapProps(
propsMapper: mapper,
): InferableComponentEnhancerWithProps;
// withProps: https://github.com/acdlite/recompose/blob/master/docs/API.md#withprops
export function withProps(
createProps: TInner | mapper,
): InferableComponentEnhancerWithProps;
// withPropsOnChange: https://github.com/acdlite/recompose/blob/master/docs/API.md#withpropsonchange
export function withPropsOnChange(
shouldMapOrKeys: string[] | predicateDiff,
createProps: mapper,
): InferableComponentEnhancerWithProps;
// withHandlers: https://github.com/acdlite/recompose/blob/master/docs/API.md#withhandlers
type EventHandler = Function;
// This type is required to infer TOutter
type HandleCreatorsStructure = {
[handlerName: string]: mapper;
};
// This type is required to infer THandlers
type HandleCreatorsHandlers = {
[P in keyof THandlers]: (props: TOutter) => THandlers[P];
};
type HandleCreators =
& HandleCreatorsStructure
& HandleCreatorsHandlers;
type HandleCreatorsFactory = (initialProps: TOutter) => HandleCreators;
export function withHandlers(
handlerCreators:
| HandleCreators
| HandleCreatorsFactory,
): InferableComponentEnhancerWithProps;
// defaultProps: https://github.com/acdlite/recompose/blob/master/docs/API.md#defaultprops
export function defaultProps(
props: T,
): DefaultingInferableComponentEnhancer;
// renameProp: https://github.com/acdlite/recompose/blob/master/docs/API.md#renameProp
export function renameProp(
outterName: string,
innerName: string,
): ComponentEnhancer;
// renameProps: https://github.com/acdlite/recompose/blob/master/docs/API.md#renameProps
type NameMap = {
[outterName: string]: string;
};
export function renameProps(
nameMap: NameMap,
): ComponentEnhancer;
// flattenProp: https://github.com/acdlite/recompose/blob/master/docs/API.md#flattenProp
export function flattenProp(
propName: string,
): ComponentEnhancer;
// withState: https://github.com/acdlite/recompose/blob/master/docs/API.md#withState
type stateProps<
TState,
TStateName extends string,
TStateUpdaterName extends string,
> =
& { [stateName in TStateName]: TState }
& { [stateUpdateName in TStateUpdaterName]: (state: TState) => TState };
export function withState<
TOutter,
TState,
TStateName extends string,
TStateUpdaterName extends string,
>(
stateName: TStateName,
stateUpdaterName: TStateUpdaterName,
initialState: TState | mapper,
): InferableComponentEnhancerWithProps<
stateProps,
TOutter
>;
// withStateHandlers: https://github.com/acdlite/recompose/blob/master/docs/API.md#withstatehandlers
type StateHandler = (...payload: any[]) => Partial | undefined;
type StateHandlerMap = {
[updaterName: string]: StateHandler;
};
type StateUpdaters = {
[updaterName in keyof TUpdaters]: (state: TState, props: TOutter) => TUpdaters[updaterName];
};
export function withStateHandlers, TOutter = {}>(
createProps: TState | mapper,
stateUpdaters: StateUpdaters,
): InferableComponentEnhancerWithProps;
// withReducer: https://github.com/acdlite/recompose/blob/master/docs/API.md#withReducer
type reducer = (s: TState, a: TAction) => TState;
type reducerProps<
TState,
TAction,
TStateName extends string,
TDispatchName extends string,
> =
& { [stateName in TStateName]: TState }
& { [dispatchName in TDispatchName]: (a: TAction) => void };
export function withReducer<
TOutter,
TState,
TAction,
TStateName extends string,
TDispatchName extends string,
>(
stateName: TStateName,
dispatchName: TDispatchName,
reducer: reducer,
initialState: TState | mapper,
): InferableComponentEnhancerWithProps<
reducerProps,
TOutter
>;
// branch: https://github.com/acdlite/recompose/blob/master/docs/API.md#branch
export function branch(
test: predicate,
trueEnhancer: ComponentEnhancer | InferableComponentEnhancer<{}>,
falseEnhancer?: ComponentEnhancer | InferableComponentEnhancer<{}>,
): ComponentEnhancer;
// renderComponent: https://github.com/acdlite/recompose/blob/master/docs/API.md#renderComponent
export function renderComponent(
component: string | Component,
): ComponentEnhancer;
// renderNothing: https://github.com/acdlite/recompose/blob/master/docs/API.md#renderNothing
export const renderNothing: InferableComponentEnhancer<{}>;
// shouldUpdate: https://github.com/acdlite/recompose/blob/master/docs/API.md#shouldUpdate
export function shouldUpdate(
test: predicateDiff,
): InferableComponentEnhancer<{}>;
// pure: https://github.com/acdlite/recompose/blob/master/docs/API.md#pure
export function pure(component: Component): Component;
// onlyUpdateForKeys: https://github.com/acdlite/recompose/blob/master/docs/API.md#onlyUpdateForKeys
export function onlyUpdateForKeys(
propKeys: string[],
): InferableComponentEnhancer<{}>;
export function onlyUpdateForKeys(
propKeys: Array,
): InferableComponentEnhancer<{}>;
// onlyUpdateForPropTypes: https://github.com/acdlite/recompose/blob/master/docs/API.md#onlyUpdateForPropTypes
export const onlyUpdateForPropTypes: InferableComponentEnhancer<{}>;
// withContext: https://github.com/acdlite/recompose/blob/master/docs/API.md#withContext
export function withContext(
childContextTypes: PropTypes.ValidationMap,
getChildContext: mapper,
): InferableComponentEnhancer<{}>;
// getContext: https://github.com/acdlite/recompose/blob/master/docs/API.md#getContext
export function getContext(
contextTypes: PropTypes.ValidationMap,
): InferableComponentEnhancer;
interface _ReactLifeCycleFunctionsThisArguments {
props: TProps;
state: TState;
setState(
f: (prevState: TState, props: TProps) => Pick,
callback?: () => any,
): void;
setState(state: Pick, callback?: () => any): void;
forceUpdate(callBack?: () => any): void;
context: any;
refs: {
[key: string]: React.ReactInstance;
};
}
type ReactLifeCycleFunctionsThisArguments =
& _ReactLifeCycleFunctionsThisArguments
& TInstance;
// lifecycle: https://github.com/acdlite/recompose/blob/master/docs/API.md#lifecycle
interface ReactLifeCycleFunctions {
componentWillMount?:
| ((this: ReactLifeCycleFunctionsThisArguments) => void)
| undefined;
UNSAFE_componentWillMount?(this: ReactLifeCycleFunctionsThisArguments): void;
componentDidMount?:
| ((this: ReactLifeCycleFunctionsThisArguments) => void)
| undefined;
componentWillReceiveProps?:
| ((this: ReactLifeCycleFunctionsThisArguments, nextProps: TProps) => void)
| undefined;
UNSAFE_componentWillReceiveProps?(
this: ReactLifeCycleFunctionsThisArguments,
nextProps: TProps,
): void;
shouldComponentUpdate?:
| ((
this: ReactLifeCycleFunctionsThisArguments,
nextProps: TProps,
nextState: TState,
) => boolean)
| undefined;
componentWillUpdate?:
| ((
this: ReactLifeCycleFunctionsThisArguments,
nextProps: TProps,
nextState: TState,
) => void)
| undefined;
UNSAFE_componentWillUpdate?(
this: ReactLifeCycleFunctionsThisArguments,
nextProps: TProps,
nextState: TState,
): void;
componentDidUpdate?:
| ((
this: ReactLifeCycleFunctionsThisArguments,
prevProps: TProps,
prevState: TState,
) => void)
| undefined;
componentWillUnmount?:
| ((this: ReactLifeCycleFunctionsThisArguments) => void)
| undefined;
componentDidCatch?:
| ((
this: ReactLifeCycleFunctionsThisArguments,
error: Error,
info: React.ErrorInfo,
) => void)
| undefined;
}
export function lifecycle(
spec: ReactLifeCycleFunctions & TInstance,
): InferableComponentEnhancer<{}>;
// toClass: https://github.com/acdlite/recompose/blob/master/docs/API.md#toClass
export const toClass: InferableComponentEnhancer<{}>;
// toRenderProps: https://github.com/acdlite/recompose/blob/master/docs/API.md#torenderprops
export function toRenderProps(
hoc: InferableComponentEnhancerWithProps,
): FunctionComponent React.ReactElement }>;
// fromRenderProps: https://github.com/acdlite/recompose/blob/master/docs/API.md#fromrenderprops
export function fromRenderProps(
RenderPropsComponent: Component,
propsMapper: (props: TRenderProps) => TInner,
renderPropName?: string,
): ComponentEnhancer;
// Static property helpers: https://github.com/acdlite/recompose/blob/master/docs/API.md#static-property-helpers
// setStatic: https://github.com/acdlite/recompose/blob/master/docs/API.md#setStatic
export function setStatic(
key: string,
value: any,
): >(component: T) => T;
// setPropTypes: https://github.com/acdlite/recompose/blob/master/docs/API.md#setPropTypes
export function setPropTypes