next-redux-wrapper: Provides its own types (#39478)

* next-redux-wrapper: Provides its own types

* use @types/next-redux-wrapper in next-redux-saga

* fix CI error related to dependencies resolutions
This commit is contained in:
Alexander T
2019-11-18 08:36:25 -08:00
committed by Nathan Shively-Sanders
parent cdf01cf33d
commit 134bb19cf8
8 changed files with 11 additions and 151 deletions
+6
View File
@@ -2856,6 +2856,12 @@
"sourceRepoURL": "https://github.com/sindresorhus/new-github-release-url",
"asOfVersion": "1.0.0"
},
{
"libraryName": "next-redux-wrapper",
"typingsPackageName": "next-redux-wrapper",
"sourceRepoURL": "https://github.com/kirill-konshin/next-redux-wrapper",
"asOfVersion": "3.0.0"
},
{
"libraryName": "next",
"typingsPackageName": "next",
@@ -3,6 +3,10 @@ import withRedux from 'next-redux-wrapper';
import withReduxSaga from 'next-redux-saga';
import { createStore, Reducer, Store, AnyAction } from 'redux';
// `next-redux-saga` depends on `next-redux-wrapper`, which depends on `react-redux`, CI cannot detect the `react-redux` and install it.
// Adding an explicit `react-redux` fix the issue.
import * as ReactRedux from 'react-redux';
interface InitialState {
foo: string;
}
+1
View File
@@ -1,6 +1,7 @@
{
"private": true,
"dependencies": {
"@types/next-redux-wrapper": "^2.0.2",
"redux": "^3.6.0"
}
}
-50
View File
@@ -1,50 +0,0 @@
// Type definitions for next-redux-wrapper 2.0
// Project: https://github.com/kirill-konshin/next-redux-wrapper
// Definitions by: Steve <https://github.com/stevegeek>
// Jungwoo-An <https://github.com/Jungwoo-An>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
/// <reference types="node" />
import { IncomingMessage, ServerResponse } from 'http';
import { ComponentType } from 'react';
import {
MapDispatchToPropsParam, MapStateToPropsParam,
MergeProps, Options as ConnectOptions
} from 'react-redux';
import { Store } from 'redux';
declare namespace nextReduxWrapper {
interface Options {
storeKey?: string;
debug?: boolean;
serializeState?: any;
deserializeState?: any;
}
interface StoreCreatorOptions<TInitialState, TStateProps, TDispatchProps, TOwnProps, TMergedProps> extends Options {
isServer: boolean;
req?: IncomingMessage;
res?: ServerResponse;
query?: any;
}
interface NextPageComponentMethods {
getInitialProps(props: any): Promise<any>;
}
type NextReduxWrappedComponent<P> = ComponentType<P> & NextPageComponentMethods;
type NextStoreCreator<TInitialState, TStateProps, TDispatchProps, TOwnProps, TMergedProps> = (
initialState: TInitialState,
options: StoreCreatorOptions<TInitialState, TStateProps, TDispatchProps, TOwnProps, TMergedProps>
) => Store<TInitialState>;
}
declare function nextReduxWrapper<TInitialState = any, TStateProps = any, TDispatchProps = any, TOwnProps = any, TMergedProps = any>(
makeStore: nextReduxWrapper.NextStoreCreator<TInitialState, TStateProps, TDispatchProps, TOwnProps, TMergedProps>,
config?: nextReduxWrapper.Options
): (ComponentType: ComponentType<TOwnProps & TMergedProps>) => nextReduxWrapper.NextReduxWrappedComponent<TOwnProps>;
export default nextReduxWrapper;
@@ -1,64 +0,0 @@
import * as React from 'react';
import withRedux from 'next-redux-wrapper';
import { createStore, Reducer, Store, AnyAction } from 'redux';
interface InitialState {
foo: string;
}
const reducer: Reducer<InitialState> = (state: InitialState = { foo: '' }, action: AnyAction): InitialState => {
switch (action.type) {
case 'FOO':
return { ...state, foo: action.payload };
default:
return state;
}
};
const makeStore = (initialState: InitialState): Store<InitialState> => {
return createStore(reducer, initialState);
};
interface OwnProps {
bar: string;
}
interface Props {
foo: string;
custom: string;
}
class Page extends React.Component<OwnProps & Props> {
static getInitialProps({ store, isServer, pathname, query }: any) {
store.dispatch({ type: 'FOO', payload: 'foo' });
return { custom: 'custom' };
}
render() {
return (
<div>
<div>Prop from Redux {this.props.foo}</div>
<div>Prop from getInitialProps {this.props.custom}</div>
</div>
);
}
}
type ConnectStateProps = Props;
type DispatchProps = Props;
type MergedProps = Props;
// Test various typings
const Com1 = withRedux<InitialState, ConnectStateProps, DispatchProps, OwnProps, MergedProps>(
(initialState: InitialState, options) => {
if (options.isServer || options.req || options.query || options.res) {
const a = 1;
}
return createStore(reducer, initialState);
},
)(Page);
const Com2 = withRedux(makeStore)(Page);
const com1Instance = (<Com1 bar="foo" />);
const com2Instance = (<Com2 />);
-6
View File
@@ -1,6 +0,0 @@
{
"private": true,
"dependencies": {
"redux": "^3.6.0"
}
}
-25
View File
@@ -1,25 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"jsx": "react",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"next-redux-wrapper-tests.tsx"
]
}
-6
View File
@@ -1,6 +0,0 @@
{
"extends": "dtslint/dt.json",
"rules": {
"no-unnecessary-generics": false
}
}