diff --git a/types/recompose/index.d.ts b/types/recompose/index.d.ts index 36621f3376..5fe0c82987 100644 --- a/types/recompose/index.d.ts +++ b/types/recompose/index.d.ts @@ -216,7 +216,7 @@ declare module 'recompose' { contextTypes: ValidationMap ) : InferableComponentEnhancer; - interface ReactLifeCycleFunctionsThisArguments { + interface _ReactLifeCycleFunctionsThisArguments { props: TProps, state: TState, setState(f: (prevState: TState, props: TProps) => Pick, callback?: () => any): void; @@ -228,20 +228,22 @@ declare module 'recompose' { [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; - componentDidMount?: (this: ReactLifeCycleFunctionsThisArguments) => void; - componentWillReceiveProps?: (this: ReactLifeCycleFunctionsThisArguments, nextProps: TProps) => void; - shouldComponentUpdate?: (this: ReactLifeCycleFunctionsThisArguments, nextProps: TProps, nextState: TState) => boolean; - componentWillUpdate?: (this: ReactLifeCycleFunctionsThisArguments, nextProps: TProps, nextState: TState) => void; - componentDidUpdate?: (this: ReactLifeCycleFunctionsThisArguments, prevProps: TProps, prevState: TState) => void; - componentWillUnmount?: (this: ReactLifeCycleFunctionsThisArguments) => void; + interface ReactLifeCycleFunctions { + componentWillMount?: (this: ReactLifeCycleFunctionsThisArguments) => void; + componentDidMount?: (this: ReactLifeCycleFunctionsThisArguments) => void; + componentWillReceiveProps?: (this: ReactLifeCycleFunctionsThisArguments, nextProps: TProps) => void; + shouldComponentUpdate?: (this: ReactLifeCycleFunctionsThisArguments, nextProps: TProps, nextState: TState) => boolean; + componentWillUpdate?: (this: ReactLifeCycleFunctionsThisArguments, nextProps: TProps, nextState: TState) => void; + componentDidUpdate?: (this: ReactLifeCycleFunctionsThisArguments, prevProps: TProps, prevState: TState) => void; + componentWillUnmount?: (this: ReactLifeCycleFunctionsThisArguments) => void; } - export function lifecycle( - spec: ReactLifeCycleFunctions + export function lifecycle( + spec: ReactLifeCycleFunctions & TInstance ): InferableComponentEnhancer<{}>; // toClass: https://github.com/acdlite/recompose/blob/master/docs/API.md#toClass @@ -365,7 +367,7 @@ declare module 'recompose' { export function createEventHandler>(): EventHandlerOf; // createEventHandlerWithConfig: https://github.com/acdlite/recompose/blob/master/docs/API.md#createEventHandlerWithConfig - export function createEventHandlerWithConfig(config: ObservableConfig): + export function createEventHandlerWithConfig(config: ObservableConfig): >() => EventHandlerOf; // setObservableConfig: https://github.com/acdlite/recompose/blob/master/docs/API.md#setObservableConfig diff --git a/types/recompose/recompose-tests.tsx b/types/recompose/recompose-tests.tsx index 1ed22fac20..3bffa12cc6 100644 --- a/types/recompose/recompose-tests.tsx +++ b/types/recompose/recompose-tests.tsx @@ -289,3 +289,21 @@ function testOnlyUpdateForKeys() { // This should be a compile error // onlyUpdateForKeys(['fo'])(component) } + +function testLifecycle() { + interface Props { + foo: number; + bar: string; + } + interface State {} + interface Instance { + instanceValue: number + } + const component: React.StatelessComponent = (props) =>
{props.foo} {props.bar}
+ lifecycle({ + instanceValue: 1, + componentDidMount() { + this.instanceValue = 2 + } + })(component) +}