diff --git a/types/next-redux-wrapper/index.d.ts b/types/next-redux-wrapper/index.d.ts index 41e6739294..16af858743 100644 --- a/types/next-redux-wrapper/index.d.ts +++ b/types/next-redux-wrapper/index.d.ts @@ -1,17 +1,11 @@ -// Type definitions for next-redux-wrapper 1.4 +// Type definitions for next-redux-wrapper 2.0 // Project: https://github.com/kirill-konshin/next-redux-wrapper // Definitions by: Steve +// Jungwoo-An // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 /// -/*~ Note that ES6 modules cannot directly export callable functions. - *~ This file should be imported using the CommonJS-style: - *~ import x = require('next-redux-wrapper'); - *~ - *~ Refer to the documentation to understand common - *~ workarounds for this limitation of ES6 modules. - */ import { IncomingMessage, ServerResponse } from 'http'; import { ComponentType } from 'react'; @@ -21,46 +15,34 @@ import { } from 'react-redux'; import { Store } from 'redux'; -export = nextReduxWrapper; - -declare function nextReduxWrapper( - options: nextReduxWrapper.Options -): (ComponentType: ComponentType) => nextReduxWrapper.NextReduxWrappedComponent; -declare function nextReduxWrapper( - createStore: nextReduxWrapper.NextStoreCreator, - mapStateToProps?: MapStateToPropsParam, - mapDispatchToProps?: MapDispatchToPropsParam, - mergeProps?: MergeProps, - options?: ConnectOptions -): (ComponentType: ComponentType) => nextReduxWrapper.NextReduxWrappedComponent; - declare namespace nextReduxWrapper { - interface NextPageComponentMethods { - getInitialProps(props: any): Promise; - } - type NextReduxWrappedComponent

= ComponentType

& NextPageComponentMethods; - - type NextStoreCreator = ( - initialState: TInitialState, - options: StoreCreatorOptions - ) => Store; - - interface Options { - createStore: NextStoreCreator; - debug?: boolean; + interface Options { storeKey?: string; - mapStateToProps?: MapStateToPropsParam; - mapDispatchToProps?: MapDispatchToPropsParam; - mergeProps?: MergeProps; - connectOptions?: ConnectOptions; + debug?: boolean; } - interface StoreCreatorOptions extends Options { + + interface StoreCreatorOptions extends Options { isServer: boolean; req?: IncomingMessage; res?: ServerResponse; query?: any; } - function setPromise(Promise: any): void; - function setDebug(debug: boolean): void; + interface NextPageComponentMethods { + getInitialProps(props: any): Promise; + } + + type NextReduxWrappedComponent

= ComponentType

& NextPageComponentMethods; + + type NextStoreCreator = ( + initialState: TInitialState, + options: StoreCreatorOptions + ) => Store; } + +declare function nextReduxWrapper( + makeStore: nextReduxWrapper.NextStoreCreator, + config?: nextReduxWrapper.Options +): (ComponentType: ComponentType) => nextReduxWrapper.NextReduxWrappedComponent; + +export default nextReduxWrapper; diff --git a/types/next-redux-wrapper/next-redux-wrapper-tests.tsx b/types/next-redux-wrapper/next-redux-wrapper-tests.tsx index 89e358afb2..2d338ec220 100644 --- a/types/next-redux-wrapper/next-redux-wrapper-tests.tsx +++ b/types/next-redux-wrapper/next-redux-wrapper-tests.tsx @@ -1,18 +1,17 @@ import * as React from 'react'; -import withRedux = require('next-redux-wrapper'); +import withRedux from 'next-redux-wrapper'; import { createStore, Reducer, Store, AnyAction } from 'redux'; -import { StoreCreatorOptions } from 'next-redux-wrapper'; interface InitialState { foo: string; } -const reducer: Reducer = (state: InitialState = {foo: ''}, action: AnyAction): InitialState => { +const reducer: Reducer = (state: InitialState = { foo: '' }, action: AnyAction): InitialState => { switch (action.type) { case 'FOO': - return {...state, foo: action.payload}; - default: - return state; + return { ...state, foo: action.payload }; + default: + return state; } }; @@ -29,14 +28,10 @@ interface Props { custom: string; } -interface ReduxStore { - foo: string; -} - class Page extends React.Component { - static getInitialProps({store, isServer, pathname, query}: any) { - store.dispatch({type: 'FOO', payload: 'foo'}); - return {custom: 'custom'}; + static getInitialProps({ store, isServer, pathname, query }: any) { + store.dispatch({ type: 'FOO', payload: 'foo' }); + return { custom: 'custom' }; } render() { return ( @@ -53,48 +48,17 @@ type DispatchProps = Props; type MergedProps = Props; // Test various typings -const Com1 = withRedux(makeStore, (state: ReduxStore) => ({foo: state.foo}))(Page); -const Com2 = withRedux(makeStore, (state: ReduxStore) => ({foo: state.foo}))(Page); - -const Com3 = withRedux(makeStore, (state: ReduxStore) => ({foo: state.foo}))(Page); - -const Com4 = withRedux( - makeStore, - (state: ReduxStore) => ({foo: state.foo, custom: 'hi'}) -)(Page); - -const Com5 = withRedux( - makeStore, - (state: ReduxStore) => ({foo: state.foo, custom: 'hi'}), - undefined, - (state: Props) => ({foo: state.foo, custom: 'hi'}) -)(Page); - -const Com6 = withRedux( - (initialState: InitialState, options: StoreCreatorOptions) => { +const Com1 = withRedux( + (initialState: InitialState, options) => { if (options.isServer || options.req || options.query || options.res) { const a = 1; } return createStore(reducer, initialState); }, - (state: ReduxStore) => ({foo: state.foo, custom: 'hi'}), - undefined, - (state: Props) => ({foo: state.foo, custom: 'hi'}) )(Page); -const Com7 = withRedux({ - createStore: makeStore, - mapStateToProps: (state: ReduxStore) => ({foo: state.foo}) -})(Page); +const Com2 = withRedux(makeStore)(Page); -const com1Instance = (); +const com1Instance = (); const com2Instance = (); -const com3Instance = (); -const com4Instance = (); -const com5Instance = (); -const com6Instance = (); -const com7Instance = (); - -withRedux.setPromise(Promise); -withRedux.setDebug(true);