mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add types for package react-combine-reducers (#43749)
* Add types for react-combine-reducer * Run prettier on react-combine-reducers * Fix linter issues
This commit is contained in:
parent
206382727b
commit
368934537f
13
types/react-combine-reducers/index.d.ts
vendored
Normal file
13
types/react-combine-reducers/index.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
// Type definitions for react-combine-reducers 1.0
|
||||
// Project: https://github.com/ankita1010/react-combine-reducers#readme
|
||||
// Definitions by: Raphaël Léger <https://github.com/raphael-leger>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// Minimum TypeScript Version: 3.1
|
||||
import { Reducer, ReducerState } from 'react';
|
||||
|
||||
declare function combineReducers<R extends Reducer<any, any>>(
|
||||
reducers: {
|
||||
[K in keyof ReducerState<R>]: [Reducer<ReducerState<R>[K], any>, ReducerState<R>[K]];
|
||||
},
|
||||
): [R, ReducerState<R>];
|
||||
export = combineReducers;
|
||||
232
types/react-combine-reducers/react-combine-reducers-tests.ts
Normal file
232
types/react-combine-reducers/react-combine-reducers-tests.ts
Normal file
@ -0,0 +1,232 @@
|
||||
import combineReducers from 'react-combine-reducers';
|
||||
|
||||
interface SimpleAction {
|
||||
type: string;
|
||||
payload: any;
|
||||
}
|
||||
|
||||
interface GreeniesState {
|
||||
fruit: 'apple' | 'pear' | 'kiwi';
|
||||
vegetable: 'carrot' | 'eggplant';
|
||||
}
|
||||
|
||||
interface ProteinsState {
|
||||
similiCarne: 'tofu' | 'seitan';
|
||||
vegetable: 'bean' | 'artichoke';
|
||||
}
|
||||
|
||||
interface DrinkState {
|
||||
beverage: 'water' | 'juice';
|
||||
numberOfGlasses: number;
|
||||
}
|
||||
|
||||
interface DessertState {
|
||||
cake: 'chocolate' | 'cherry';
|
||||
drink: 'tea' | 'coffee';
|
||||
}
|
||||
|
||||
interface FullMealState {
|
||||
proteins: ProteinsState;
|
||||
greenies: GreeniesState;
|
||||
dessert: DessertState;
|
||||
drink: DrinkState;
|
||||
}
|
||||
|
||||
type FullMealReducer = (state: FullMealState, action: SimpleAction) => FullMealState;
|
||||
|
||||
const proteinsReducer = (proteinsState: ProteinsState, action: SimpleAction) => {
|
||||
switch (action) {
|
||||
default:
|
||||
return proteinsState;
|
||||
}
|
||||
};
|
||||
|
||||
const drinkReducer = (drinkState: DrinkState, action: SimpleAction) => {
|
||||
switch (action) {
|
||||
default:
|
||||
return drinkState;
|
||||
}
|
||||
};
|
||||
|
||||
const dessertReducer = (dessertState: DessertState, action: SimpleAction) => {
|
||||
switch (action) {
|
||||
default:
|
||||
return dessertState;
|
||||
}
|
||||
};
|
||||
|
||||
const greeniesReducer = (greeniesState: GreeniesState, action: SimpleAction) => {
|
||||
switch (action) {
|
||||
default:
|
||||
return greeniesState;
|
||||
}
|
||||
};
|
||||
|
||||
// $ExpectError
|
||||
combineReducers('');
|
||||
|
||||
// $ExpectError
|
||||
combineReducers<FullMealReducer>({});
|
||||
|
||||
// $ExpectError
|
||||
combineReducers<FullMealReducer>();
|
||||
|
||||
combineReducers<FullMealReducer>({
|
||||
// $ExpectError
|
||||
books: ['The Book Thief'],
|
||||
});
|
||||
|
||||
combineReducers<FullMealReducer>({
|
||||
// $ExpectError
|
||||
proteins: [100],
|
||||
});
|
||||
|
||||
combineReducers<FullMealReducer>({
|
||||
// $ExpectError
|
||||
proteins: [3, proteinsReducer],
|
||||
});
|
||||
|
||||
combineReducers<FullMealReducer>({
|
||||
// $ExpectError
|
||||
proteins: [proteinsReducer, 3],
|
||||
});
|
||||
|
||||
// $ExpectError
|
||||
combineReducers<FullMealReducer>({
|
||||
proteins: [
|
||||
proteinsReducer,
|
||||
{
|
||||
similiCarne: 'tofu',
|
||||
vegetable: 'artichoke',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
combineReducers<FullMealReducer>({
|
||||
proteins: [
|
||||
proteinsReducer,
|
||||
{
|
||||
similiCarne: 'tofu',
|
||||
vegetable: 'artichoke',
|
||||
},
|
||||
],
|
||||
greenies: [
|
||||
// $ExpectError
|
||||
proteinsReducer,
|
||||
{
|
||||
fruit: 'kiwi',
|
||||
vegetable: 'eggplant',
|
||||
},
|
||||
],
|
||||
drink: [
|
||||
// $ExpectError
|
||||
proteinsReducer,
|
||||
{
|
||||
beverage: 'juice',
|
||||
numberOfGlasses: 2,
|
||||
},
|
||||
],
|
||||
dessert: [
|
||||
// $ExpectError
|
||||
proteinsReducer,
|
||||
{
|
||||
cake: 'chocolate',
|
||||
drink: 'tea',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const [fullMealReducer, initialMeal] = combineReducers<FullMealReducer>({
|
||||
proteins: [
|
||||
proteinsReducer,
|
||||
{
|
||||
similiCarne: 'tofu',
|
||||
vegetable: 'artichoke',
|
||||
},
|
||||
],
|
||||
greenies: [
|
||||
greeniesReducer,
|
||||
{
|
||||
fruit: 'kiwi',
|
||||
vegetable: 'eggplant',
|
||||
},
|
||||
],
|
||||
drink: [
|
||||
drinkReducer,
|
||||
{
|
||||
beverage: 'juice',
|
||||
numberOfGlasses: 2,
|
||||
},
|
||||
],
|
||||
dessert: [
|
||||
dessertReducer,
|
||||
{
|
||||
cake: 'chocolate',
|
||||
drink: 'tea',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
initialMeal.dessert;
|
||||
initialMeal.drink;
|
||||
initialMeal.proteins;
|
||||
initialMeal.greenies;
|
||||
|
||||
// $ExpectError
|
||||
initialMeal.lamps;
|
||||
|
||||
// $ExpectError
|
||||
fullMealReducer(3, {});
|
||||
|
||||
// $ExpectError
|
||||
fullMealReducer({}, {});
|
||||
|
||||
fullMealReducer(
|
||||
{
|
||||
proteins: {
|
||||
similiCarne: 'tofu',
|
||||
vegetable: 'artichoke',
|
||||
},
|
||||
greenies: {
|
||||
fruit: 'kiwi',
|
||||
vegetable: 'eggplant',
|
||||
},
|
||||
drink: {
|
||||
beverage: 'juice',
|
||||
numberOfGlasses: 2,
|
||||
},
|
||||
dessert: {
|
||||
cake: 'chocolate',
|
||||
drink: 'tea',
|
||||
},
|
||||
},
|
||||
// $ExpectError
|
||||
67,
|
||||
);
|
||||
|
||||
fullMealReducer(
|
||||
{
|
||||
proteins: {
|
||||
similiCarne: 'tofu',
|
||||
vegetable: 'artichoke',
|
||||
},
|
||||
greenies: {
|
||||
fruit: 'kiwi',
|
||||
vegetable: 'eggplant',
|
||||
},
|
||||
drink: {
|
||||
beverage: 'juice',
|
||||
numberOfGlasses: 2,
|
||||
},
|
||||
dessert: {
|
||||
cake: 'chocolate',
|
||||
drink: 'tea',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'eat',
|
||||
payload: 'everything',
|
||||
},
|
||||
);
|
||||
|
||||
export { fullMealReducer, initialMeal };
|
||||
24
types/react-combine-reducers/tsconfig.json
Normal file
24
types/react-combine-reducers/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"esModuleInterop": true,
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"react-combine-reducers-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/react-combine-reducers/tslint.json
Normal file
1
types/react-combine-reducers/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user