DefinitelyTyped/types/react-side-effect/index.d.ts
Martin Charles 03212af7da [react-side-effect] Removed Any Types (#27132)
* Improved react-side-effect Typings

Removed all `any` typings. Added tests which test usage.

* Made Lint Less Permissive

It doesn't need to be so permissive.

* Fixed Whitespace

* Added Typings for Server Stuff

Used a more robust way than suggested in review. Added tests too.

* Fixed Server Types

`peek` can return either a `TServerState` or `TState` when `withSideEffect` is
provided `mapStateOnServer` (based on runtime). `rewind` always returns
`TServerState` when `mapStateOnServer` is provided, otherwise it returns
`TState`.
2018-07-23 10:10:12 -07:00

35 lines
1.2 KiB
TypeScript

// Type definitions for react-side-effect 1.1
// Project: https://github.com/gaearon/react-side-effect
// Definitions by: Remo H. Jansen <https://github.com/remojansen>
// Martin Charles <https://github.com/0xcaff>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
import * as React from "react";
interface WithSideEffect {
<TProp, TState>(
reducePropsToState: (propsList: TProp[]) => TState,
handleStateChangeOnClient: (state: TState) => void
): ClassDecorator<TProp, TState, TState>;
<TProp, TState, TServerState>(
reducePropsToState: (propsList: TProp[]) => TState,
handleStateChangeOnClient: (state: TState) => void,
mapStateOnServer: (state: TState) => TServerState
): ClassDecorator<TProp, TState | TServerState, TServerState>;
}
declare const withSideEffect: WithSideEffect;
type ClassDecorator<TProp, TPeek, TRewind> = (
component: React.ComponentType<TProp>
) => React.ComponentType<TProp> & {
peek: () => TPeek;
rewind: () => TRewind;
};
declare namespace withSideEffect {} // https://github.com/Microsoft/TypeScript/issues/5073
export = withSideEffect;