Add types for redux-cablecar (#38944)

* Add types for redux-cablecar

* Make payload for the perform function optional
This commit is contained in:
Christoph Flick 2019-10-11 01:26:17 +02:00 committed by Armando Aguirre
parent 84d4755cb5
commit 4c52cecef4
5 changed files with 78 additions and 0 deletions

30
types/redux-cablecar/index.d.ts vendored Normal file
View File

@ -0,0 +1,30 @@
// Type definitions for redux-cablecar 3.0
// Project: https://github.com/ndhays/redux-cablecar#readme
// Definitions by: Christoph Flick <https://github.com/ChFlick>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
import { Action, Middleware, Store } from 'redux';
export interface Options {
connected?: () => void;
disconnected?: () => void;
params?: object;
prefix?: string;
optimisticOnFail?: boolean;
}
export interface CableCar {
changeChannel: (channel: string, options?: Options) => void;
getChannel: () => string;
getParams: () => object;
perform: (method: string, payload?: any) => void;
send: (action: string) => void;
}
declare var middleware: Middleware & {
connect: (store: Store, channel: string, options?: Options) => CableCar;
setProvider: (actionCableProvider: string) => void;
};
export default middleware;

View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"redux": "^4.0.4"
}
}

View File

@ -0,0 +1,18 @@
import cablecar, { Options } from 'redux-cablecar';
import { applyMiddleware, createStore } from 'redux';
const store = createStore(() => null, applyMiddleware(cablecar));
cablecar.setProvider('testProvider');
const car = cablecar.connect(store, 'testChannel');
const options: Options = {
connected: () => { },
prefix: 'ASDF'
};
const anotherCar = cablecar.connect(store, 'secondeTestChannel', options);
car.perform('activate', { data: 'something' });
anotherCar.send('noice_action');

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"redux-cablecar-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }