mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-03-27 22:49:20 +08:00
Add next-redux-saga types (#29383)
* Add next-redux-saga types * Add TypeScript version * Matching TS version of React * Sort by specific overload * Fixes after npm run test * Declare redux dependency * Statically typed createStore * For new packages, this file should only "extends": "dtslint/dt.json" * require(next-redux-saga) is itself a function, not an object with a default property * Enable ES Module Interop
This commit is contained in:
12
types/next-redux-saga/index.d.ts
vendored
Normal file
12
types/next-redux-saga/index.d.ts
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
// Type definitions for next-redux-saga 3.0
|
||||
// Project: https://github.com/bmealhouse/next-redux-saga
|
||||
// Definitions by: Leo Cavalcante <https://github.com/leocavalcante>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { ComponentType } from "react";
|
||||
|
||||
declare function nextReduxSaga<P = any>(arg: { async: boolean }): ((BaseComponent: ComponentType<P>) => ComponentType<P>);
|
||||
declare function nextReduxSaga<P = any>(arg: ComponentType<P>): ComponentType<P>;
|
||||
|
||||
export = nextReduxSaga;
|
||||
65
types/next-redux-saga/next-redux-saga-tests.tsx
Normal file
65
types/next-redux-saga/next-redux-saga-tests.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
import * as React from 'react';
|
||||
import withRedux from 'next-redux-wrapper';
|
||||
import withReduxSaga from 'next-redux-saga';
|
||||
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<InitialState>(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);
|
||||
},
|
||||
)(withReduxSaga<OwnProps & Props>({ async: true })(Page));
|
||||
|
||||
const Com2 = withRedux(makeStore)(withReduxSaga(Page));
|
||||
|
||||
const com1Instance = (<Com1 bar="foo" />);
|
||||
const com2Instance = (<Com2 />);
|
||||
6
types/next-redux-saga/package.json
Normal file
6
types/next-redux-saga/package.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"redux": "^3.6.0"
|
||||
}
|
||||
}
|
||||
26
types/next-redux-saga/tsconfig.json
Normal file
26
types/next-redux-saga/tsconfig.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"jsx": "react",
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"next-redux-saga-tests.tsx"
|
||||
]
|
||||
}
|
||||
3
types/next-redux-saga/tslint.json
Normal file
3
types/next-redux-saga/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user