Skip to content
This repository has been archived by the owner on Sep 16, 2020. It is now read-only.

Tests for TS typings #16

Merged
merged 6 commits into from Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Expand Up @@ -128,5 +128,3 @@ $RECYCLE.BIN/

# End of https://www.gitignore.io/api/node,windows,linux,macos
lib/*

!lib/index.d.ts
25 changes: 0 additions & 25 deletions lib/index.d.ts

This file was deleted.

135 changes: 135 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -4,12 +4,14 @@
"description": "Write your actions and reducers without pain",
"main": "lib/index.js",
"scripts": {
"test": "eslint . && nyc ava",
"test": "eslint . && nyc ava && npm run types",
"types": "rm -rf node_modules && npm i -g dtslint && dtslint types",
"build": "babel ./src -d ./lib",
"coverage": "NODE_ENV=test nyc report --reporter=text-lcov",
"report": "nyc report --reporter=text-lcov | coveralls",
"prepublish": "npm run build"
},
"types": "types",
"files": [
"lib",
"src"
Expand Down Expand Up @@ -46,6 +48,7 @@
"@babel/preset-env": "^7.0.0",
"ava": "^0.25.0",
"coveralls": "^3.0.1",
"dtslint": "^0.3.0",
"eslint": "^4.19.1",
"nyc": "^12.0.2"
}
Expand Down
31 changes: 31 additions & 0 deletions types/index.d.ts
@@ -0,0 +1,31 @@
// TypeScript Version: 2.8

export interface NamespaceOptions<State> {
namespace?: string;
defaultReducer?: (prevState: State) => State;
separator?: string;
}

export type Symbiote<State> = ((state: State, ...payload: any[]) => State);

export type Reducer<State> = (state: State, action: Action) => State;

export type ActionsConfig<State, Actions> = {
[Key in keyof Actions]: Actions[Key] extends Function // tslint:disable-line
? Symbiote<State>
: ActionsConfig<State, Actions[Key]>
};

export interface Action<Payload = any> {
type: string;
payload?: Payload;
}

export function createSymbiote<State, Actions>(
initialState: State,
actionsConfig: ActionsConfig<State, Actions>,
namespaceOptions?: string | NamespaceOptions<State>,
): {
actions: Actions,
reducer: Reducer<State>,
};