From 1fd50de2753b81d140a4d46c315a984ed6f9aac7 Mon Sep 17 00:00:00 2001 From: Piotr Witek Date: Sun, 21 Apr 2019 04:31:25 +0200 Subject: [PATCH] Updated TA build in sandbox --- codesandbox/src/typesafe-actions/action.d.ts | 18 ++--- .../create-action-deprecated.d.ts | 8 +- .../src/typesafe-actions/create-action.d.ts | 6 +- .../typesafe-actions/create-async-action.d.ts | 8 +- .../create-custom-action.d.ts | 4 +- .../src/typesafe-actions/create-reducer.d.ts | 79 +++---------------- .../create-standard-action.d.ts | 6 +- .../src/typesafe-actions/get-type.d.ts | 4 +- codesandbox/src/typesafe-actions/index.d.ts | 2 +- codesandbox/src/typesafe-actions/index.esm.js | 6 +- codesandbox/src/typesafe-actions/index.js | 6 +- .../src/typesafe-actions/index.umd.js.map | 2 +- .../src/typesafe-actions/type-helpers.d.ts | 76 +++++++++--------- .../typesafe-actions/utils/validation.d.ts | 8 +- 14 files changed, 85 insertions(+), 148 deletions(-) diff --git a/codesandbox/src/typesafe-actions/action.d.ts b/codesandbox/src/typesafe-actions/action.d.ts index 5467671..2a1c302 100644 --- a/codesandbox/src/typesafe-actions/action.d.ts +++ b/codesandbox/src/typesafe-actions/action.d.ts @@ -1,37 +1,37 @@ -import { StringType } from './type-helpers'; -export declare function action(type: T, payload: undefined, meta: undefined, error: E): { +import { TypeConstant } from './type-helpers'; +export declare function action(type: T, payload: undefined, meta: undefined, error: E): { type: T; error: E; }; -export declare function action(type: T, payload: undefined, meta: M, error: E): { +export declare function action(type: T, payload: undefined, meta: M, error: E): { type: T; meta: M; error: E; }; -export declare function action(type: T, payload: P, meta: undefined, error: E): { +export declare function action(type: T, payload: P, meta: undefined, error: E): { type: T; payload: P; error: E; }; -export declare function action(type: T, payload: P, meta: M, error: E): { +export declare function action(type: T, payload: P, meta: M, error: E): { type: T; payload: P; meta: M; error: E; }; -export declare function action(type: T, payload: undefined, meta: M): { +export declare function action(type: T, payload: undefined, meta: M): { type: T; meta: M; }; -export declare function action(type: T, payload: P, meta: M): { +export declare function action(type: T, payload: P, meta: M): { type: T; payload: P; meta: M; }; -export declare function action(type: T, payload: P): { +export declare function action(type: T, payload: P): { type: T; payload: P; }; -export declare function action(type: T): { +export declare function action(type: T): { type: T; }; diff --git a/codesandbox/src/typesafe-actions/create-action-deprecated.d.ts b/codesandbox/src/typesafe-actions/create-action-deprecated.d.ts index 4f89330..a72d19d 100644 --- a/codesandbox/src/typesafe-actions/create-action-deprecated.d.ts +++ b/codesandbox/src/typesafe-actions/create-action-deprecated.d.ts @@ -1,12 +1,12 @@ -import { StringType } from './type-helpers'; -interface FSA { +import { TypeConstant } from './type-helpers'; +interface FSA { type: T; payload?: P; meta?: M; error?: E; } -export declare function createActionDeprecated FSA>(actionType: T, creatorFunction: AC): AC; -export declare function createActionDeprecated { +export declare function createActionDeprecated FSA>(actionType: T, creatorFunction: AC): AC; +export declare function createActionDeprecated { type: T; }>(actionType: T): AC; export {}; diff --git a/codesandbox/src/typesafe-actions/create-action.d.ts b/codesandbox/src/typesafe-actions/create-action.d.ts index ee83974..c50741b 100644 --- a/codesandbox/src/typesafe-actions/create-action.d.ts +++ b/codesandbox/src/typesafe-actions/create-action.d.ts @@ -1,5 +1,5 @@ -import { StringType, ActionCreator } from './type-helpers'; -export declare type PayloadMetaAction = P extends undefined ? M extends undefined ? { +import { TypeConstant, ActionCreator } from './type-helpers'; +export declare type PayloadMetaAction = P extends undefined ? M extends undefined ? { type: T; } : { type: T; @@ -12,6 +12,6 @@ export declare type PayloadMetaAction = P extends un payload: P; meta: M; }; -export declare function createAction = () => { +export declare function createAction = () => { type: T; }>(type: T, createHandler?: (actionCallback:

(payload?: P, meta?: M) => PayloadMetaAction) => AC): AC; diff --git a/codesandbox/src/typesafe-actions/create-async-action.d.ts b/codesandbox/src/typesafe-actions/create-async-action.d.ts index c8911f6..04df07c 100644 --- a/codesandbox/src/typesafe-actions/create-async-action.d.ts +++ b/codesandbox/src/typesafe-actions/create-async-action.d.ts @@ -1,10 +1,10 @@ -import { StringType, ActionBuilderConstructor } from './type-helpers'; -export interface AsyncActionBuilder { +import { TypeConstant, ActionBuilderConstructor } from './type-helpers'; +export interface AsyncActionBuilder { (): AsyncActionBuilderConstructor; } -export declare type AsyncActionBuilderConstructor = { +export declare type AsyncActionBuilderConstructor = { request: ActionBuilderConstructor; success: ActionBuilderConstructor; failure: ActionBuilderConstructor; }; -export declare function createAsyncAction(requestType: T1, successType: T2, failureType: T3): AsyncActionBuilder; +export declare function createAsyncAction(requestType: T1, successType: T2, failureType: T3): AsyncActionBuilder; diff --git a/codesandbox/src/typesafe-actions/create-custom-action.d.ts b/codesandbox/src/typesafe-actions/create-custom-action.d.ts index e7895cf..a268ad5 100644 --- a/codesandbox/src/typesafe-actions/create-custom-action.d.ts +++ b/codesandbox/src/typesafe-actions/create-custom-action.d.ts @@ -1,4 +1,4 @@ -import { ActionCreator, StringType } from './type-helpers'; -export declare function createCustomAction = () => { +import { ActionCreator, TypeConstant } from './type-helpers'; +export declare function createCustomAction = () => { type: T; }>(type: T, createHandler?: (type: T) => AC): AC; diff --git a/codesandbox/src/typesafe-actions/create-reducer.d.ts b/codesandbox/src/typesafe-actions/create-reducer.d.ts index 52739a9..c044b64 100644 --- a/codesandbox/src/typesafe-actions/create-reducer.d.ts +++ b/codesandbox/src/typesafe-actions/create-reducer.d.ts @@ -1,70 +1,11 @@ -import { RootAction } from '.'; -export declare function createReducer(initialState: S): ((state: S, action: A) => S) & { - addHandler: A, TCreatorAction extends A extends ReturnType ? A : never, TActionIntersection extends TTypeAction extends TCreatorAction ? TTypeAction : never>(actionsTypes: TType | TCreator | TType[] | TCreator[], actionsHandler: (state: S, action: TActionIntersection) => S) => Exclude extends never ? (state: S, action: A) => S : ((state: S, action: A) => S) & { - addHandler: ["type"], TTypeAction extends Exclude extends { - type: TType; - } ? { - type: TType; - } & Exclude : never, TCreator extends (...args: any[]) => Exclude, TCreatorAction extends Exclude extends ReturnType ? ReturnType & Exclude : never, TActionIntersection extends TTypeAction extends TCreatorAction ? TTypeAction : never>(actionsTypes: TType | TCreator | TType[] | TCreator[], actionsHandler: (state: S, action: TActionIntersection) => S) => Exclude, TTypeAction & TCreatorAction> extends never ? (state: S, action: A) => S : ((state: S, action: A) => S) & { - addHandler: , TTypeAction & TCreatorAction>["type"], TTypeAction extends Exclude, TTypeAction & TCreatorAction> extends { - type: TType; - } ? { - type: TType; - } & Exclude, TTypeAction & TCreatorAction> : never, TCreator extends (...args: any[]) => Exclude, TTypeAction & TCreatorAction>, TCreatorAction extends Exclude, TTypeAction & TCreatorAction> extends ReturnType ? ReturnType & Exclude, TTypeAction & TCreatorAction> : never, TActionIntersection extends TTypeAction extends TCreatorAction ? TTypeAction : never>(actionsTypes: TType | TCreator | TType[] | TCreator[], actionsHandler: (state: S, action: TActionIntersection) => S) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends never ? (state: S, action: A) => S : ((state: S, action: A) => S) & { - addHandler: , TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>["type"], TTypeAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends { - type: TType; - } ? { - type: TType; - } & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TCreator extends (...args: any[]) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TCreatorAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends ReturnType ? ReturnType & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TActionIntersection extends TTypeAction extends TCreatorAction ? TTypeAction : never>(actionsTypes: TType | TCreator | TType[] | TCreator[], actionsHandler: (state: S, action: TActionIntersection) => S) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends never ? (state: S, action: A) => S : ((state: S, action: A) => S) & { - addHandler: , TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>["type"], TTypeAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends { - type: TType; - } ? { - type: TType; - } & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TCreator extends (...args: any[]) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TCreatorAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends ReturnType ? ReturnType & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TActionIntersection extends TTypeAction extends TCreatorAction ? TTypeAction : never>(actionsTypes: TType | TCreator | TType[] | TCreator[], actionsHandler: (state: S, action: TActionIntersection) => S) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends never ? (state: S, action: A) => S : ((state: S, action: A) => S) & { - addHandler: , TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>["type"], TTypeAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends { - type: TType; - } ? { - type: TType; - } & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TCreator extends (...args: any[]) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TCreatorAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends ReturnType ? ReturnType & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TActionIntersection extends TTypeAction extends TCreatorAction ? TTypeAction : never>(actionsTypes: TType | TCreator | TType[] | TCreator[], actionsHandler: (state: S, action: TActionIntersection) => S) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends never ? (state: S, action: A) => S : ((state: S, action: A) => S) & { - addHandler: , TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>["type"], TTypeAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends { - type: TType; - } ? { - type: TType; - } & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TCreator extends (...args: any[]) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TCreatorAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends ReturnType ? ReturnType & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TActionIntersection extends TTypeAction extends TCreatorAction ? TTypeAction : never>(actionsTypes: TType | TCreator | TType[] | TCreator[], actionsHandler: (state: S, action: TActionIntersection) => S) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends never ? (state: S, action: A) => S : ((state: S, action: A) => S) & { - addHandler: , TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>["type"], TTypeAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends { - type: TType; - } ? { - type: TType; - } & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TCreator extends (...args: any[]) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TCreatorAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends ReturnType ? ReturnType & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TActionIntersection extends TTypeAction extends TCreatorAction ? TTypeAction : never>(actionsTypes: TType | TCreator | TType[] | TCreator[], actionsHandler: (state: S, action: TActionIntersection) => S) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends never ? (state: S, action: A) => S : ((state: S, action: A) => S) & { - addHandler: , TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>["type"], TTypeAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends { - type: TType; - } ? { - type: TType; - } & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TCreator extends (...args: any[]) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TCreatorAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends ReturnType ? ReturnType & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TActionIntersection extends TTypeAction extends TCreatorAction ? TTypeAction : never>(actionsTypes: TType | TCreator | TType[] | TCreator[], actionsHandler: (state: S, action: TActionIntersection) => S) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends never ? (state: S, action: A) => S : ((state: S, action: A) => S) & { - addHandler: , TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>["type"], TTypeAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends { - type: TType; - } ? { - type: TType; - } & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TCreator extends (...args: any[]) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TCreatorAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends ReturnType ? ReturnType & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TActionIntersection extends TTypeAction extends TCreatorAction ? TTypeAction : never>(actionsTypes: TType | TCreator | TType[] | TCreator[], actionsHandler: (state: S, action: TActionIntersection) => S) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends never ? (state: S, action: A) => S : ((state: S, action: A) => S) & { - addHandler: , TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>["type"], TTypeAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends { - type: TType; - } ? { - type: TType; - } & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TCreator extends (...args: any[]) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TCreatorAction extends Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends ReturnType ? ReturnType & Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> : never, TActionIntersection extends TTypeAction extends TCreatorAction ? TTypeAction : never>(actionsTypes: TType | TCreator | TType[] | TCreator[], actionsHandler: (state: S, action: TActionIntersection) => S) => Exclude, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction>, TTypeAction & TCreatorAction> extends never ? (state: S, action: A) => S : ((state: S, action: A) => S) & { - addHandler: any; - }; - }; - }; - }; - }; - }; - }; - }; - }; - }; - }; +import { RootAction } from './'; +import { Reducer, Action } from './type-helpers'; +declare type AddHandler = TAllActions, TCreatorAction extends TAllActions extends ReturnType ? TAllActions : never, TActionIntersection extends TTypeAction extends TCreatorAction ? TTypeAction : never>(actionsTypes: TType | TCreator | TType[] | TCreator[], actionsHandler: (state: S, action: TActionIntersection) => S) => Exclude extends never ? Reducer : Reducer & { + addHandler: AddHandler>; }; +export declare function createReducer(initialState: S): Reducer & { + addHandler: AddHandler; +}; +export {}; diff --git a/codesandbox/src/typesafe-actions/create-standard-action.d.ts b/codesandbox/src/typesafe-actions/create-standard-action.d.ts index 610723b..bf99567 100644 --- a/codesandbox/src/typesafe-actions/create-standard-action.d.ts +++ b/codesandbox/src/typesafe-actions/create-standard-action.d.ts @@ -1,6 +1,6 @@ -import { StringType, ActionBuilderConstructor, ActionBuilderMap } from './type-helpers'; -export interface ActionBuilder { +import { TypeConstant, ActionBuilderConstructor, ActionBuilderMap } from './type-helpers'; +export interface ActionBuilder {

(): ActionBuilderConstructor; map(fn: (payload: P, meta: M) => R): ActionBuilderMap; } -export declare function createStandardAction(type: T): ActionBuilder; +export declare function createStandardAction(type: T): ActionBuilder; diff --git a/codesandbox/src/typesafe-actions/get-type.d.ts b/codesandbox/src/typesafe-actions/get-type.d.ts index 1230a5b..ad4bdae 100644 --- a/codesandbox/src/typesafe-actions/get-type.d.ts +++ b/codesandbox/src/typesafe-actions/get-type.d.ts @@ -1,2 +1,2 @@ -import { StringType, ActionCreator, TypeMeta } from './type-helpers'; -export declare function getType(actionCreator: ActionCreator & TypeMeta): T; +import { TypeConstant, ActionCreator, TypeMeta } from './type-helpers'; +export declare function getType(actionCreator: ActionCreator & TypeMeta): T; diff --git a/codesandbox/src/typesafe-actions/index.d.ts b/codesandbox/src/typesafe-actions/index.d.ts index 49d6938..7f4b94e 100644 --- a/codesandbox/src/typesafe-actions/index.d.ts +++ b/codesandbox/src/typesafe-actions/index.d.ts @@ -7,5 +7,5 @@ export { createReducer } from './create-reducer'; export { getType } from './get-type'; export { isOfType } from './is-of-type'; export { isActionOf } from './is-action-of'; -export { ActionType, StateType, ActionCreator, TypeMeta } from './type-helpers'; +export { TypeConstant, Action, ActionCreator, Reducer, EmptyAction, PayloadAction, MetaAction, PayloadMetaAction, EmptyAC, PayloadAC, PayloadMetaAC, TypeMeta, ActionType, StateType, } from './type-helpers'; export { createActionDeprecated } from './create-action-deprecated'; diff --git a/codesandbox/src/typesafe-actions/index.esm.js b/codesandbox/src/typesafe-actions/index.esm.js index b9e8b3f..02cb244 100644 --- a/codesandbox/src/typesafe-actions/index.esm.js +++ b/codesandbox/src/typesafe-actions/index.esm.js @@ -158,12 +158,12 @@ function createReducer(initialState) { : throwInvalidActionTypeOrActionCreator(); }) .forEach(function (type) { return (handlers[type] = actionsHandler); }); - return chain; + return chainApi; }); - var chain = Object.assign(reducer, { + var chainApi = Object.assign(reducer, { addHandler: addHandler, }); - return chain; + return chainApi; } function isOfType(actionTypeOrTypes, action) { diff --git a/codesandbox/src/typesafe-actions/index.js b/codesandbox/src/typesafe-actions/index.js index f6cb39b..8136b31 100644 --- a/codesandbox/src/typesafe-actions/index.js +++ b/codesandbox/src/typesafe-actions/index.js @@ -162,12 +162,12 @@ function createReducer(initialState) { : throwInvalidActionTypeOrActionCreator(); }) .forEach(function (type) { return (handlers[type] = actionsHandler); }); - return chain; + return chainApi; }); - var chain = Object.assign(reducer, { + var chainApi = Object.assign(reducer, { addHandler: addHandler, }); - return chain; + return chainApi; } function isOfType(actionTypeOrTypes, action) { diff --git a/codesandbox/src/typesafe-actions/index.umd.js.map b/codesandbox/src/typesafe-actions/index.umd.js.map index 49be7f7..8b0345d 100644 --- a/codesandbox/src/typesafe-actions/index.umd.js.map +++ b/codesandbox/src/typesafe-actions/index.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"index.umd.js","sources":["../src/utils/validation.ts","../src/action.ts","../src/create-custom-action.ts","../src/get-type.ts","../src/create-action.ts","../src/create-standard-action.ts","../src/create-async-action.ts","../src/create-reducer.ts","../src/is-of-type.ts","../src/is-action-of.ts","../src/create-action-deprecated.ts"],"sourcesContent":["import { ActionCreator, TypeMeta, StringType } from '../type-helpers';\n\nexport function checkIsEmpty(arg: unknown, argPosition: number = 1) {\n return arg == null;\n}\n\nexport function throwIsEmpty(argPosition: number = 1): never {\n throw new Error(`Argument ${argPosition} is empty.`);\n}\n\nexport function checkValidActionCreator(\n arg: unknown\n): arg is ActionCreator {\n return typeof arg === 'function' && 'getType' in arg;\n}\n\nexport function checkInvalidActionCreator(arg: unknown) {\n return !checkValidActionCreator(arg);\n}\n\nexport function throwInvalidActionCreator(argPosition: number = 1): never {\n throw new Error(\n `Argument ${argPosition} is invalid, it should be an action-creator instance from \"typesafe-actions\"`\n );\n}\n\nexport function checkInvalidActionCreatorInArray(\n arg: ActionCreator & TypeMeta,\n idx: number\n): void | never {\n if (arg == null) {\n throw new Error(\n `Argument contains array with empty element at index ${idx}`\n );\n } else if (arg.getType == null) {\n throw new Error(\n // tslint:disable-next-line:max-line-length\n `Argument contains array with invalid element at index ${idx}, it should be an action-creator instance from \"typesafe-actions\"`\n );\n }\n}\n\nexport function checkValidActionType(arg: unknown): arg is string | symbol {\n return typeof arg === 'string' || typeof arg === 'symbol';\n}\n\nexport function checkInvalidActionType(arg: unknown): arg is string | symbol {\n return !checkValidActionType(arg);\n}\n\nexport function throwInvalidActionType(argPosition: number = 1): never {\n throw new Error(\n `Argument ${argPosition} is invalid, it should be an action type of type: string | symbol`\n );\n}\n\nexport function checkInvalidActionTypeInArray(\n arg: StringType,\n idx: number\n): void | never {\n if (arg == null) {\n throw new Error(\n `Argument contains array with empty element at index ${idx}`\n );\n } else if (typeof arg !== 'string' && typeof arg !== 'symbol') {\n throw new Error(\n `Argument contains array with invalid element at index ${idx}, it should be of type: string | symbol`\n );\n }\n}\n\nexport function throwInvalidActionTypeOrActionCreator(\n argPosition: number = 1\n): never {\n throw new Error(\n `Argument ${argPosition} is invalid, it should be an action-creator instance from \"typesafe-actions\" or action type of type: string | symbol`\n );\n}\n","import { StringType } from './type-helpers';\nimport {\n checkIsEmpty,\n throwIsEmpty,\n checkInvalidActionType,\n throwInvalidActionCreator,\n} from './utils/validation';\n\nexport function action(\n type: T,\n payload: undefined,\n meta: undefined,\n error: E\n): { type: T; error: E };\n\nexport function action(\n type: T,\n payload: undefined,\n meta: M,\n error: E\n): { type: T; meta: M; error: E };\n\nexport function action(\n type: T,\n payload: P,\n meta: undefined,\n error: E\n): { type: T; payload: P; error: E };\n\nexport function action(\n type: T,\n payload: P,\n meta: M,\n error: E\n): { type: T; payload: P; meta: M; error: E };\n\nexport function action(\n type: T,\n payload: undefined,\n meta: M\n): { type: T; meta: M };\n\nexport function action(\n type: T,\n payload: P,\n meta: M\n): { type: T; payload: P; meta: M };\n\nexport function action(\n type: T,\n payload: P\n): { type: T; payload: P };\n\nexport function action(type: T): { type: T };\n\n/**\n * @description flux standard action factory\n * @example\n * ```\n * const add = (amount: number, meta?: MetaShape) => action('INCREMENT', amount, meta);\n * ```\n */\nexport function action<\n T extends StringType,\n P = undefined,\n M = undefined,\n E = undefined\n>(type: T, payload?: P, meta?: M, error?: E) {\n if (checkIsEmpty(type)) {\n throwIsEmpty(1);\n }\n\n if (checkInvalidActionType(type)) {\n throwInvalidActionCreator(1);\n }\n\n return { type, payload, meta, error } as any;\n}\n","import { ActionCreator, StringType } from './type-helpers';\nimport {\n checkIsEmpty,\n throwIsEmpty,\n checkInvalidActionType,\n throwInvalidActionType,\n} from './utils/validation';\n\n/**\n * @description create custom action-creator using constructor function with injected type argument\n */\nexport function createCustomAction<\n T extends StringType,\n AC extends ActionCreator = () => { type: T }\n>(type: T, createHandler?: (type: T) => AC): AC {\n if (checkIsEmpty(type)) {\n throwIsEmpty(1);\n }\n\n if (checkInvalidActionType(type)) {\n throwInvalidActionType(1);\n }\n\n const actionCreator: AC =\n createHandler != null ? createHandler(type) : ((() => ({ type })) as AC);\n\n return Object.assign(actionCreator, {\n getType: () => type,\n // redux-actions compatibility\n toString: () => type,\n });\n}\n","import { StringType, ActionCreator, TypeMeta } from './type-helpers';\nimport {\n checkIsEmpty,\n throwIsEmpty,\n checkInvalidActionCreator,\n throwInvalidActionCreator,\n} from './utils/validation';\n\n/**\n * @description get the \"type literal\" of a given action-creator\n */\nexport function getType(\n actionCreator: ActionCreator & TypeMeta\n): T {\n if (checkIsEmpty(actionCreator)) {\n throwIsEmpty(1);\n }\n\n if (checkInvalidActionCreator(actionCreator)) {\n throwInvalidActionCreator(1);\n }\n\n return actionCreator.getType!();\n}\n","import { StringType, ActionCreator } from './type-helpers';\nimport { action } from './action';\n\nexport type PayloadMetaAction = P extends undefined\n ? M extends undefined\n ? { type: T }\n : { type: T; meta: M }\n : M extends undefined\n ? { type: T; payload: P }\n : { type: T; payload: P; meta: M };\n\n/**\n * @description typesafe action-creator factory\n */\nexport function createAction<\n T extends StringType,\n AC extends ActionCreator = () => { type: T }\n>(\n type: T,\n createHandler?: (\n actionCallback:

(\n payload?: P,\n meta?: M\n ) => PayloadMetaAction\n ) => AC\n): AC {\n // validation is already done in action function\n\n const actionCreator: AC =\n createHandler == null\n ? ((() => action(type)) as AC)\n : createHandler(action.bind(null, type) as Parameters<\n typeof createHandler\n >[0]);\n\n return Object.assign(actionCreator, {\n getType: () => type,\n // redux-actions compatibility\n toString: () => type,\n });\n}\n","import {\n StringType,\n ActionBuilderConstructor,\n ActionBuilderMap,\n} from './type-helpers';\nimport { createCustomAction } from './create-custom-action';\nimport {\n checkIsEmpty,\n throwIsEmpty,\n checkInvalidActionType,\n throwInvalidActionType,\n} from './utils/validation';\n\nexport interface ActionBuilder {\n

(): ActionBuilderConstructor;\n map(\n fn: (payload: P, meta: M) => R\n ): ActionBuilderMap;\n}\n\n/**\n * @description create an action-creator of a given function that contains hidden \"type\" metadata\n */\nexport function createStandardAction(\n type: T\n): ActionBuilder {\n if (checkIsEmpty(type)) {\n throwIsEmpty(1);\n }\n\n if (checkInvalidActionType(type)) {\n throwInvalidActionType(1);\n }\n\n function constructor(): ActionBuilderConstructor {\n return createCustomAction(type, _type => (payload: P, meta: M) => ({\n type: _type,\n payload,\n meta,\n })) as ActionBuilderConstructor;\n }\n\n function map(\n fn: (payload: P, meta: M) => R\n ): ActionBuilderMap {\n return createCustomAction(type, _type => (payload: P, meta: M) =>\n Object.assign(fn(payload, meta), { type: _type })\n ) as ActionBuilderMap;\n }\n\n return Object.assign(constructor, { map });\n}\n","import {\n StringType,\n ActionBuilderConstructor,\n // ActionBuilderMap,\n} from './type-helpers';\nimport { createCustomAction } from './create-custom-action';\nimport { checkInvalidActionTypeInArray } from './utils/validation';\n\nexport interface AsyncActionBuilder<\n T1 extends StringType,\n T2 extends StringType,\n T3 extends StringType\n> {\n // tslint:disable-next-line:callable-types\n (): AsyncActionBuilderConstructor;\n // withMappers(\n // requestMapper: (a?: A1) => P1,\n // successMapper: (a?: A2) => P2,\n // failureMapper: (a?: A3) => P3\n // ): AsyncActionBuilderWithMappers;\n}\n\nexport type AsyncActionBuilderConstructor<\n T1 extends StringType,\n T2 extends StringType,\n T3 extends StringType,\n P1,\n P2,\n P3\n> = {\n request: ActionBuilderConstructor;\n success: ActionBuilderConstructor;\n failure: ActionBuilderConstructor;\n};\n\n/**\n * implementation\n */\nexport function createAsyncAction<\n T1 extends StringType,\n T2 extends StringType,\n T3 extends StringType\n>(\n requestType: T1,\n successType: T2,\n failureType: T3\n): AsyncActionBuilder {\n [requestType, successType, failureType].forEach(\n checkInvalidActionTypeInArray\n );\n\n function constructor(): AsyncActionBuilderConstructor<\n T1,\n T2,\n T3,\n P1,\n P2,\n P3\n > {\n return {\n request: createCustomAction(requestType, type => (payload?: P1) => ({\n type,\n payload,\n })) as ActionBuilderConstructor,\n success: createCustomAction(successType, type => (payload?: P2) => ({\n type,\n payload,\n })) as ActionBuilderConstructor,\n failure: createCustomAction(failureType, type => (payload?: P3) => ({\n type,\n payload,\n })) as ActionBuilderConstructor,\n };\n }\n\n return Object.assign(constructor);\n}\n\n// export type AsyncActionBuilderWithMappers<\n// T1 extends StringType,\n// T2 extends StringType,\n// T3 extends StringType,\n// A1 = undefined,\n// P1 = undefined,\n// A2 = undefined,\n// P2 = undefined,\n// A3 = undefined,\n// P3 = undefined\n// > = {\n// request: ActionBuilderMap;\n// success: ActionBuilderMap;\n// failure: ActionBuilderMap;\n// };\n\n// function withMappers(\n// requestMapper: (a?: A1) => P1,\n// successMapper: (a?: A2) => P2,\n// failureMapper: (a?: A3) => P3\n// ): AsyncActionBuilderWithMappers {\n// return {\n// request: createCustomAction(requestType, type => (payload?: A1) => ({\n// type,\n// payload: requestMapper != null ? requestMapper(payload) : undefined,\n// })) as MapBuilder,\n// success: createCustomAction(successType, type => (payload?: A2) => ({\n// type,\n// payload: successMapper != null ? successMapper(payload) : undefined,\n// })) as MapBuilder,\n// failure: createCustomAction(failureType, type => (payload?: A3) => ({\n// type,\n// payload: failureMapper != null ? failureMapper(payload) : undefined,\n// })) as MapBuilder,\n// };\n// }\n","// @ts-ignore\nimport { RootAction } from '.';\nimport { getType } from './get-type';\nimport {\n checkValidActionCreator,\n checkValidActionType,\n throwInvalidActionTypeOrActionCreator,\n} from './utils/validation';\n\nexport function createReducer(\n initialState: S\n) {\n type AddHandler = <\n TType extends TAllActions['type'],\n TTypeAction extends TAllActions extends { type: TType }\n ? TAllActions\n : never,\n TCreator extends (...args: any[]) => TAllActions,\n TCreatorAction extends TAllActions extends ReturnType\n ? TAllActions\n : never,\n TActionIntersection extends TTypeAction extends TCreatorAction\n ? TTypeAction\n : never\n >(\n actionsTypes: TType | TCreator | TType[] | TCreator[],\n actionsHandler: (state: S, action: TActionIntersection) => S\n ) => Exclude extends never\n ? Reducer\n : Reducer & {\n addHandler: AddHandler<\n Exclude\n >;\n };\n\n type AddHandlerChain = { addHandler: AddHandler };\n\n const handlers: Record = {};\n\n type Reducer = (state: S, action: A) => S;\n const reducer: Reducer = (state = initialState, action) => {\n if (handlers.hasOwnProperty(action.type)) {\n return handlers[action.type](state, action);\n } else {\n return state;\n }\n };\n\n const addHandler = ((actionsTypes, actionsHandler: Reducer) => {\n const creatorsOrTypes = Array.isArray(actionsTypes)\n ? actionsTypes\n : [actionsTypes];\n\n creatorsOrTypes\n .map(acOrType =>\n checkValidActionCreator(acOrType)\n ? getType(acOrType)\n : checkValidActionType(acOrType)\n ? acOrType\n : throwInvalidActionTypeOrActionCreator()\n )\n .forEach(type => (handlers[type] = actionsHandler));\n return chain;\n }) as AddHandler;\n\n const chain: Reducer & AddHandlerChain = Object.assign(reducer, {\n addHandler,\n });\n\n return chain;\n}\n","import {\n checkInvalidActionTypeInArray,\n checkIsEmpty,\n throwIsEmpty,\n} from './utils/validation';\n/**\n * @description (curried assert function) check if action type is equal given type-constant\n * @description it works with discriminated union types\n */\nexport function isOfType(\n type: T | T[],\n action: A\n): action is A extends { type: T } ? A : never;\n\n/**\n * @description (curried assert function) check if action type is equal given type-constant\n * @description it works with discriminated union types\n */\nexport function isOfType(\n type: T | T[]\n): (\n action: A\n) => action is A extends { type: T } ? A : never;\n\n/**\n * implementation\n */\nexport function isOfType(\n actionTypeOrTypes: T | T[],\n action?: A\n) {\n if (checkIsEmpty(actionTypeOrTypes)) {\n throwIsEmpty(1);\n }\n\n const actionTypes = Array.isArray(actionTypeOrTypes)\n ? actionTypeOrTypes\n : [actionTypeOrTypes];\n\n actionTypes.forEach(checkInvalidActionTypeInArray);\n\n const assertFn = (_action: A) => actionTypes.includes(_action.type);\n\n // 1 arg case => return curried version\n if (action === undefined) {\n return assertFn;\n }\n // 2 args case => invoke assertFn and return the result\n return assertFn(action);\n}\n","import { TypeMeta } from './type-helpers';\nimport {\n checkInvalidActionCreatorInArray,\n checkIsEmpty,\n throwIsEmpty,\n} from './utils/validation';\n\nexport type ActionCreator = ((\n ...args: any[]\n) => T) &\n TypeMeta;\n\n/**\n * @description (curried assert function) check if an action is the instance of given action-creator(s)\n * @description it works with discriminated union types\n */\nexport function isActionOf>(\n actionCreator: AC | AC[],\n action: { type: string }\n): action is ReturnType;\n\n/**\n * @description (curried assert function) check if an action is the instance of given action-creator(s)\n * @description it works with discriminated union types\n */\nexport function isActionOf>(\n actionCreator: AC | AC[]\n): (action: { type: string }) => action is ReturnType;\n\n/**\n * implementation\n */\nexport function isActionOf>(\n actionCreatorOrCreators: AC | AC[],\n action?: { type: string }\n) {\n if (checkIsEmpty(actionCreatorOrCreators)) {\n throwIsEmpty(1);\n }\n\n const actionCreators = Array.isArray(actionCreatorOrCreators)\n ? actionCreatorOrCreators\n : [actionCreatorOrCreators];\n\n actionCreators.forEach(checkInvalidActionCreatorInArray);\n\n const assertFn = (_action: { type: string }) =>\n actionCreators.some(\n actionCreator => _action.type === actionCreator.getType!()\n );\n\n // 1 arg case => return curried version\n if (action === undefined) {\n return assertFn;\n }\n // 2 args case => invoke assertFn and return the result\n return assertFn(action);\n}\n","/**\n * DEPRECATED\n */\n\nimport { StringType } from './type-helpers';\n\ninterface FSA {\n type: T;\n payload?: P;\n meta?: M;\n error?: E;\n}\n\n/**\n * @deprecated\n * @description create an action-creator of a given function that contains hidden \"type\" metadata\n */\nexport function createActionDeprecated<\n T extends StringType,\n AC extends (...args: any[]) => FSA\n>(actionType: T, creatorFunction: AC): AC;\n\n/**\n * @deprecated\n * @description create an action-creator of a given function that contains hidden \"type\" metadata\n */\nexport function createActionDeprecated<\n T extends StringType,\n AC extends () => { type: T }\n>(actionType: T): AC;\n\n/**\n * implementation\n */\nexport function createActionDeprecated<\n T extends StringType,\n AC extends (...args: any[]) => FSA\n>(actionType: T, creatorFunction?: AC): AC {\n let actionCreator: AC;\n\n if (creatorFunction != null) {\n if (typeof creatorFunction !== 'function') {\n throw new Error('second argument is not a function');\n }\n\n actionCreator = creatorFunction as AC;\n } else {\n actionCreator = (() => ({ type: actionType })) as AC;\n }\n\n if (actionType != null) {\n if (typeof actionType !== 'string' && typeof actionType !== 'symbol') {\n throw new Error('first argument should be type of: string | symbol');\n }\n } else {\n throw new Error('first argument is missing');\n }\n\n return actionCreator;\n}\n"],"names":["checkIsEmpty","arg","argPosition","throwIsEmpty","Error","checkValidActionCreator","throwInvalidActionCreator","checkInvalidActionCreatorInArray","idx","getType","checkValidActionType","checkInvalidActionType","throwInvalidActionType","checkInvalidActionTypeInArray","action","type","payload","meta","error","createCustomAction","createHandler","actionCreator","Object","assign","toString","bind","_type","map","fn","requestType","successType","failureType","forEach","request","success","failure","initialState","handlers","chain","state","hasOwnProperty","addHandler","actionsTypes","actionsHandler","Array","isArray","acOrType","throwInvalidActionTypeOrActionCreator","actionTypeOrTypes","actionTypes","assertFn","_action","includes","undefined","actionCreatorOrCreators","actionCreators","some","actionType","creatorFunction"],"mappings":"2MAEgBA,EAAaC,EAAcC,GACzC,oBADyCA,KAC3B,MAAPD,WAGOE,EAAaD,GAC3B,mBAD2BA,KACrB,IAAIE,MAAM,YAAYF,yBAGdG,EACdJ,GAEA,MAAsB,mBAARA,GAAsB,YAAaA,WAOnCK,EAA0BJ,GACxC,mBADwCA,KAClC,IAAIE,MACR,YAAYF,2FAIAK,EACdN,EACAO,GAEA,GAAW,MAAPP,EACF,MAAM,IAAIG,MACR,uDAAuDI,GAEpD,GAAmB,MAAfP,EAAIQ,QACb,MAAM,IAAIL,MAER,yDAAyDI,gFAK/CE,EAAqBT,GACnC,MAAsB,iBAARA,GAAmC,iBAARA,WAG3BU,EAAuBV,GACrC,OAAQS,EAAqBT,YAGfW,EAAuBV,GACrC,mBADqCA,KAC/B,IAAIE,MACR,YAAYF,gFAIAW,EACdZ,EACAO,GAE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EAAgBqC,OAEhBrC,aAAuB,OAAGN,KAAM0C,IAGlC,GAAkB,MAAdA,EAKF,MAAM,IAAIrD,MAAM,6BAJhB,GAA0B,iBAAfqD,GAAiD,iBAAfA,EAC3C,MAAM,IAAIrD,MAAM,qDAMpB,OAAOiB"} \ No newline at end of file +{"version":3,"file":"index.umd.js","sources":["../src/utils/validation.ts","../src/action.ts","../src/create-custom-action.ts","../src/get-type.ts","../src/create-action.ts","../src/create-standard-action.ts","../src/create-async-action.ts","../src/create-reducer.ts","../src/is-of-type.ts","../src/is-action-of.ts","../src/create-action-deprecated.ts"],"sourcesContent":["import { ActionCreator, TypeMeta, TypeConstant } from '../type-helpers';\n\nexport function checkIsEmpty(arg: unknown, argPosition: number = 1) {\n return arg == null;\n}\n\nexport function throwIsEmpty(argPosition: number = 1): never {\n throw new Error(`Argument ${argPosition} is empty.`);\n}\n\nexport function checkValidActionCreator(\n arg: unknown\n): arg is ActionCreator {\n return typeof arg === 'function' && 'getType' in arg;\n}\n\nexport function checkInvalidActionCreator(arg: unknown) {\n return !checkValidActionCreator(arg);\n}\n\nexport function throwInvalidActionCreator(argPosition: number = 1): never {\n throw new Error(\n `Argument ${argPosition} is invalid, it should be an action-creator instance from \"typesafe-actions\"`\n );\n}\n\nexport function checkInvalidActionCreatorInArray(\n arg: ActionCreator & TypeMeta,\n idx: number\n): void | never {\n if (arg == null) {\n throw new Error(\n `Argument contains array with empty element at index ${idx}`\n );\n } else if (arg.getType == null) {\n throw new Error(\n // tslint:disable-next-line:max-line-length\n `Argument contains array with invalid element at index ${idx}, it should be an action-creator instance from \"typesafe-actions\"`\n );\n }\n}\n\nexport function checkValidActionType(arg: unknown): arg is string | symbol {\n return typeof arg === 'string' || typeof arg === 'symbol';\n}\n\nexport function checkInvalidActionType(arg: unknown): arg is string | symbol {\n return !checkValidActionType(arg);\n}\n\nexport function throwInvalidActionType(argPosition: number = 1): never {\n throw new Error(\n `Argument ${argPosition} is invalid, it should be an action type of type: string | symbol`\n );\n}\n\nexport function checkInvalidActionTypeInArray(\n arg: TypeConstant,\n idx: number\n): void | never {\n if (arg == null) {\n throw new Error(\n `Argument contains array with empty element at index ${idx}`\n );\n } else if (typeof arg !== 'string' && typeof arg !== 'symbol') {\n throw new Error(\n `Argument contains array with invalid element at index ${idx}, it should be of type: string | symbol`\n );\n }\n}\n\nexport function throwInvalidActionTypeOrActionCreator(\n argPosition: number = 1\n): never {\n throw new Error(\n `Argument ${argPosition} is invalid, it should be an action-creator instance from \"typesafe-actions\" or action type of type: string | symbol`\n );\n}\n","import { TypeConstant } from './type-helpers';\nimport {\n checkIsEmpty,\n throwIsEmpty,\n checkInvalidActionType,\n throwInvalidActionCreator,\n} from './utils/validation';\n\nexport function action(\n type: T,\n payload: undefined,\n meta: undefined,\n error: E\n): { type: T; error: E };\n\nexport function action(\n type: T,\n payload: undefined,\n meta: M,\n error: E\n): { type: T; meta: M; error: E };\n\nexport function action(\n type: T,\n payload: P,\n meta: undefined,\n error: E\n): { type: T; payload: P; error: E };\n\nexport function action(\n type: T,\n payload: P,\n meta: M,\n error: E\n): { type: T; payload: P; meta: M; error: E };\n\nexport function action(\n type: T,\n payload: undefined,\n meta: M\n): { type: T; meta: M };\n\nexport function action(\n type: T,\n payload: P,\n meta: M\n): { type: T; payload: P; meta: M };\n\nexport function action(\n type: T,\n payload: P\n): { type: T; payload: P };\n\nexport function action(type: T): { type: T };\n\n/**\n * @description flux standard action factory\n * @example\n * ```\n * const add = (amount: number, meta?: MetaShape) => action('INCREMENT', amount, meta);\n * ```\n */\nexport function action<\n T extends TypeConstant,\n P = undefined,\n M = undefined,\n E = undefined\n>(type: T, payload?: P, meta?: M, error?: E) {\n if (checkIsEmpty(type)) {\n throwIsEmpty(1);\n }\n\n if (checkInvalidActionType(type)) {\n throwInvalidActionCreator(1);\n }\n\n return { type, payload, meta, error } as any;\n}\n","import { ActionCreator, TypeConstant } from './type-helpers';\nimport {\n checkIsEmpty,\n throwIsEmpty,\n checkInvalidActionType,\n throwInvalidActionType,\n} from './utils/validation';\n\n/**\n * @description create custom action-creator using constructor function with injected type argument\n */\nexport function createCustomAction<\n T extends TypeConstant,\n AC extends ActionCreator = () => { type: T }\n>(type: T, createHandler?: (type: T) => AC): AC {\n if (checkIsEmpty(type)) {\n throwIsEmpty(1);\n }\n\n if (checkInvalidActionType(type)) {\n throwInvalidActionType(1);\n }\n\n const actionCreator: AC =\n createHandler != null ? createHandler(type) : ((() => ({ type })) as AC);\n\n return Object.assign(actionCreator, {\n getType: () => type,\n // redux-actions compatibility\n toString: () => type,\n });\n}\n","import { TypeConstant, ActionCreator, TypeMeta } from './type-helpers';\nimport {\n checkIsEmpty,\n throwIsEmpty,\n checkInvalidActionCreator,\n throwInvalidActionCreator,\n} from './utils/validation';\n\n/**\n * @description get the \"type literal\" of a given action-creator\n */\nexport function getType(\n actionCreator: ActionCreator & TypeMeta\n): T {\n if (checkIsEmpty(actionCreator)) {\n throwIsEmpty(1);\n }\n\n if (checkInvalidActionCreator(actionCreator)) {\n throwInvalidActionCreator(1);\n }\n\n return actionCreator.getType!();\n}\n","import { TypeConstant, ActionCreator } from './type-helpers';\nimport { action } from './action';\n\nexport type PayloadMetaAction<\n T extends TypeConstant,\n P,\n M\n> = P extends undefined\n ? M extends undefined\n ? { type: T }\n : { type: T; meta: M }\n : M extends undefined\n ? { type: T; payload: P }\n : { type: T; payload: P; meta: M };\n\n/**\n * @description typesafe action-creator factory\n */\nexport function createAction<\n T extends TypeConstant,\n AC extends ActionCreator = () => { type: T }\n>(\n type: T,\n createHandler?: (\n actionCallback:

(\n payload?: P,\n meta?: M\n ) => PayloadMetaAction\n ) => AC\n): AC {\n // validation is already done in action function\n\n const actionCreator: AC =\n createHandler == null\n ? ((() => action(type)) as AC)\n : createHandler(action.bind(null, type) as Parameters<\n typeof createHandler\n >[0]);\n\n return Object.assign(actionCreator, {\n getType: () => type,\n // redux-actions compatibility\n toString: () => type,\n });\n}\n","import {\n TypeConstant,\n ActionBuilderConstructor,\n ActionBuilderMap,\n} from './type-helpers';\nimport { createCustomAction } from './create-custom-action';\nimport {\n checkIsEmpty,\n throwIsEmpty,\n checkInvalidActionType,\n throwInvalidActionType,\n} from './utils/validation';\n\nexport interface ActionBuilder {\n

(): ActionBuilderConstructor;\n map(\n fn: (payload: P, meta: M) => R\n ): ActionBuilderMap;\n}\n\n/**\n * @description create an action-creator of a given function that contains hidden \"type\" metadata\n */\nexport function createStandardAction(\n type: T\n): ActionBuilder {\n if (checkIsEmpty(type)) {\n throwIsEmpty(1);\n }\n\n if (checkInvalidActionType(type)) {\n throwInvalidActionType(1);\n }\n\n function constructor(): ActionBuilderConstructor {\n return createCustomAction(type, _type => (payload: P, meta: M) => ({\n type: _type,\n payload,\n meta,\n })) as ActionBuilderConstructor;\n }\n\n function map(\n fn: (payload: P, meta: M) => R\n ): ActionBuilderMap {\n return createCustomAction(type, _type => (payload: P, meta: M) =>\n Object.assign(fn(payload, meta), { type: _type })\n ) as ActionBuilderMap;\n }\n\n return Object.assign(constructor, { map });\n}\n","import {\n TypeConstant,\n ActionBuilderConstructor,\n // ActionBuilderMap,\n} from './type-helpers';\nimport { createCustomAction } from './create-custom-action';\nimport { checkInvalidActionTypeInArray } from './utils/validation';\n\nexport interface AsyncActionBuilder<\n T1 extends TypeConstant,\n T2 extends TypeConstant,\n T3 extends TypeConstant\n> {\n // tslint:disable-next-line:callable-types\n (): AsyncActionBuilderConstructor;\n // withMappers(\n // requestMapper: (a?: A1) => P1,\n // successMapper: (a?: A2) => P2,\n // failureMapper: (a?: A3) => P3\n // ): AsyncActionBuilderWithMappers;\n}\n\nexport type AsyncActionBuilderConstructor<\n T1 extends TypeConstant,\n T2 extends TypeConstant,\n T3 extends TypeConstant,\n P1,\n P2,\n P3\n> = {\n request: ActionBuilderConstructor;\n success: ActionBuilderConstructor;\n failure: ActionBuilderConstructor;\n};\n\n/**\n * implementation\n */\nexport function createAsyncAction<\n T1 extends TypeConstant,\n T2 extends TypeConstant,\n T3 extends TypeConstant\n>(\n requestType: T1,\n successType: T2,\n failureType: T3\n): AsyncActionBuilder {\n [requestType, successType, failureType].forEach(\n checkInvalidActionTypeInArray\n );\n\n function constructor(): AsyncActionBuilderConstructor<\n T1,\n T2,\n T3,\n P1,\n P2,\n P3\n > {\n return {\n request: createCustomAction(requestType, type => (payload?: P1) => ({\n type,\n payload,\n })) as ActionBuilderConstructor,\n success: createCustomAction(successType, type => (payload?: P2) => ({\n type,\n payload,\n })) as ActionBuilderConstructor,\n failure: createCustomAction(failureType, type => (payload?: P3) => ({\n type,\n payload,\n })) as ActionBuilderConstructor,\n };\n }\n\n return Object.assign(constructor);\n}\n\n// export type AsyncActionBuilderWithMappers<\n// T1 extends StringType,\n// T2 extends StringType,\n// T3 extends StringType,\n// A1 = undefined,\n// P1 = undefined,\n// A2 = undefined,\n// P2 = undefined,\n// A3 = undefined,\n// P3 = undefined\n// > = {\n// request: ActionBuilderMap;\n// success: ActionBuilderMap;\n// failure: ActionBuilderMap;\n// };\n\n// function withMappers(\n// requestMapper: (a?: A1) => P1,\n// successMapper: (a?: A2) => P2,\n// failureMapper: (a?: A3) => P3\n// ): AsyncActionBuilderWithMappers {\n// return {\n// request: createCustomAction(requestType, type => (payload?: A1) => ({\n// type,\n// payload: requestMapper != null ? requestMapper(payload) : undefined,\n// })) as MapBuilder,\n// success: createCustomAction(successType, type => (payload?: A2) => ({\n// type,\n// payload: successMapper != null ? successMapper(payload) : undefined,\n// })) as MapBuilder,\n// failure: createCustomAction(failureType, type => (payload?: A3) => ({\n// type,\n// payload: failureMapper != null ? failureMapper(payload) : undefined,\n// })) as MapBuilder,\n// };\n// }\n","// @ts-ignore\nimport { RootAction } from './';\nimport { getType } from './get-type';\nimport {\n checkValidActionCreator,\n checkValidActionType,\n throwInvalidActionTypeOrActionCreator,\n} from './utils/validation';\nimport { Reducer, Action } from './type-helpers';\n\ntype AddHandler = <\n TType extends TAllActions['type'],\n TTypeAction extends TAllActions extends { type: TType } ? TAllActions : never,\n TCreator extends (...args: any[]) => TAllActions,\n TCreatorAction extends TAllActions extends ReturnType\n ? TAllActions\n : never,\n TActionIntersection extends TTypeAction extends TCreatorAction\n ? TTypeAction\n : never\n>(\n actionsTypes: TType | TCreator | TType[] | TCreator[],\n actionsHandler: (state: S, action: TActionIntersection) => S\n) => Exclude extends never\n ? Reducer\n : Reducer & {\n addHandler: AddHandler<\n S,\n Exclude\n >;\n };\n\nexport function createReducer(\n initialState: S\n) {\n const handlers: Record S> = {};\n\n const reducer: Reducer = (state = initialState, action) => {\n if (handlers.hasOwnProperty(action.type)) {\n return handlers[action.type](state, action);\n } else {\n return state;\n }\n };\n\n const addHandler = ((actionsTypes, actionsHandler) => {\n const creatorsOrTypes = Array.isArray(actionsTypes)\n ? actionsTypes\n : [actionsTypes];\n\n creatorsOrTypes\n .map(acOrType =>\n checkValidActionCreator(acOrType)\n ? getType(acOrType)\n : checkValidActionType(acOrType)\n ? acOrType\n : throwInvalidActionTypeOrActionCreator()\n )\n .forEach(type => (handlers[type] = actionsHandler));\n\n return chainApi;\n }) as AddHandler;\n\n const chainApi: Reducer & {\n addHandler: AddHandler;\n } = Object.assign(reducer, {\n addHandler,\n });\n\n return chainApi;\n}\n","import {\n checkInvalidActionTypeInArray,\n checkIsEmpty,\n throwIsEmpty,\n} from './utils/validation';\n/**\n * @description (curried assert function) check if action type is equal given type-constant\n * @description it works with discriminated union types\n */\nexport function isOfType(\n type: T | T[],\n action: A\n): action is A extends { type: T } ? A : never;\n\n/**\n * @description (curried assert function) check if action type is equal given type-constant\n * @description it works with discriminated union types\n */\nexport function isOfType(\n type: T | T[]\n): (\n action: A\n) => action is A extends { type: T } ? A : never;\n\n/**\n * implementation\n */\nexport function isOfType(\n actionTypeOrTypes: T | T[],\n action?: A\n) {\n if (checkIsEmpty(actionTypeOrTypes)) {\n throwIsEmpty(1);\n }\n\n const actionTypes = Array.isArray(actionTypeOrTypes)\n ? actionTypeOrTypes\n : [actionTypeOrTypes];\n\n actionTypes.forEach(checkInvalidActionTypeInArray);\n\n const assertFn = (_action: A) => actionTypes.includes(_action.type);\n\n // 1 arg case => return curried version\n if (action === undefined) {\n return assertFn;\n }\n // 2 args case => invoke assertFn and return the result\n return assertFn(action);\n}\n","import { TypeMeta } from './type-helpers';\nimport {\n checkInvalidActionCreatorInArray,\n checkIsEmpty,\n throwIsEmpty,\n} from './utils/validation';\n\nexport type ActionCreator = ((\n ...args: any[]\n) => T) &\n TypeMeta;\n\n/**\n * @description (curried assert function) check if an action is the instance of given action-creator(s)\n * @description it works with discriminated union types\n */\nexport function isActionOf>(\n actionCreator: AC | AC[],\n action: { type: string }\n): action is ReturnType;\n\n/**\n * @description (curried assert function) check if an action is the instance of given action-creator(s)\n * @description it works with discriminated union types\n */\nexport function isActionOf>(\n actionCreator: AC | AC[]\n): (action: { type: string }) => action is ReturnType;\n\n/**\n * implementation\n */\nexport function isActionOf>(\n actionCreatorOrCreators: AC | AC[],\n action?: { type: string }\n) {\n if (checkIsEmpty(actionCreatorOrCreators)) {\n throwIsEmpty(1);\n }\n\n const actionCreators = Array.isArray(actionCreatorOrCreators)\n ? actionCreatorOrCreators\n : [actionCreatorOrCreators];\n\n actionCreators.forEach(checkInvalidActionCreatorInArray);\n\n const assertFn = (_action: { type: string }) =>\n actionCreators.some(\n actionCreator => _action.type === actionCreator.getType!()\n );\n\n // 1 arg case => return curried version\n if (action === undefined) {\n return assertFn;\n }\n // 2 args case => invoke assertFn and return the result\n return assertFn(action);\n}\n","/**\n * DEPRECATED\n */\n\nimport { TypeConstant } from './type-helpers';\n\ninterface FSA {\n type: T;\n payload?: P;\n meta?: M;\n error?: E;\n}\n\n/**\n * @deprecated\n * @description create an action-creator of a given function that contains hidden \"type\" metadata\n */\nexport function createActionDeprecated<\n T extends TypeConstant,\n AC extends (...args: any[]) => FSA\n>(actionType: T, creatorFunction: AC): AC;\n\n/**\n * @deprecated\n * @description create an action-creator of a given function that contains hidden \"type\" metadata\n */\nexport function createActionDeprecated<\n T extends TypeConstant,\n AC extends () => { type: T }\n>(actionType: T): AC;\n\n/**\n * implementation\n */\nexport function createActionDeprecated<\n T extends TypeConstant,\n AC extends (...args: any[]) => FSA\n>(actionType: T, creatorFunction?: AC): AC {\n let actionCreator: AC;\n\n if (creatorFunction != null) {\n if (typeof creatorFunction !== 'function') {\n throw new Error('second argument is not a function');\n }\n\n actionCreator = creatorFunction as AC;\n } else {\n actionCreator = (() => ({ type: actionType })) as AC;\n }\n\n if (actionType != null) {\n if (typeof actionType !== 'string' && typeof actionType !== 'symbol') {\n throw new Error('first argument should be type of: string | symbol');\n }\n } else {\n throw new Error('first argument is missing');\n }\n\n return actionCreator;\n}\n"],"names":["checkIsEmpty","arg","argPosition","throwIsEmpty","Error","checkValidActionCreator","throwInvalidActionCreator","checkInvalidActionCreatorInArray","idx","getType","checkValidActionType","checkInvalidActionType","throwInvalidActionType","checkInvalidActionTypeInArray","action","type","payload","meta","error","createCustomAction","createHandler","actionCreator","Object","assign","toString","bind","_type","map","fn","requestType","successType","failureType","forEach","request","success","failure","initialState","handlers","chainApi","state","hasOwnProperty","addHandler","actionsTypes","actionsHandler","Array","isArray","acOrType","throwInvalidActionTypeOrActionCreator","actionTypeOrTypes","actionTypes","assertFn","_action","includes","undefined","actionCreatorOrCreators","actionCreators","some","actionType","creatorFunction"],"mappings":"2MAEgBA,EAAaC,EAAcC,GACzC,oBADyCA,KAC3B,MAAPD,WAGOE,EAAaD,GAC3B,mBAD2BA,KACrB,IAAIE,MAAM,YAAYF,yBAGdG,EACdJ,GAEA,MAAsB,mBAARA,GAAsB,YAAaA,WAOnCK,EAA0BJ,GACxC,mBADwCA,KAClC,IAAIE,MACR,YAAYF,2FAIAK,EACdN,EACAO,GAEA,GAAW,MAAPP,EACF,MAAM,IAAIG,MACR,uDAAuDI,GAEpD,GAAmB,MAAfP,EAAIQ,QACb,MAAM,IAAIL,MAER,yDAAyDI,gFAK/CE,EAAqBT,GACnC,MAAsB,iBAARA,GAAmC,iBAARA,WAG3BU,EAAuBV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GACf,IAAIrC,EAEJ,GAAuB,MAAnBqC,EAAyB,CAC3B,GAA+B,mBAApBA,EACT,MAAM,IAAItD,MAAM,qCAGlBiB,EAAgBqC,OAEhBrC,aAAuB,OAAGN,KAAM0C,IAGlC,GAAkB,MAAdA,EAKF,MAAM,IAAIrD,MAAM,6BAJhB,GAA0B,iBAAfqD,GAAiD,iBAAfA,EAC3C,MAAM,IAAIrD,MAAM,qDAMpB,OAAOiB"} \ No newline at end of file diff --git a/codesandbox/src/typesafe-actions/type-helpers.d.ts b/codesandbox/src/typesafe-actions/type-helpers.d.ts index 2fa08c4..0fc0092 100644 --- a/codesandbox/src/typesafe-actions/type-helpers.d.ts +++ b/codesandbox/src/typesafe-actions/type-helpers.d.ts @@ -1,46 +1,42 @@ -export interface TypeMeta { - getType?: () => T; -} -export declare type ActionCreator = (...args: any[]) => { - type: T; +export declare type TypeConstant = string; +export declare type Action = { + type: TType; }; -export declare type ActionType = ActionCreatorOrMap extends ActionCreator ? ReturnType : ActionCreatorOrMap extends Record ? { - [K in keyof ActionCreatorOrMap]: ActionType; -}[keyof ActionCreatorOrMap] : ActionCreatorOrMap extends infer R ? never : never; -export declare type StateType = ReducerOrMap extends (...args: any[]) => any ? ReturnType : ReducerOrMap extends object ? { - [K in keyof ReducerOrMap]: StateType; -} : never; -export declare type StringType = string; -export declare type EmptyAction = { - type: T; +export declare type ActionCreator = (...args: any[]) => Action; +export declare type Reducer = (state: TState | undefined, action: TAction) => TState; +export declare type EmptyAction = { + type: TType; }; -export declare type PayloadAction = { - type: T; - payload: P; +export declare type PayloadAction = { + type: TType; + payload: TPayload; }; -export declare type MetaAction = { - type: T; - meta: M; +export declare type MetaAction = { + type: TType; + meta: TMeta; }; -export declare type PayloadMetaAction = { - type: T; - payload: P; - meta: M; +export declare type PayloadMetaAction = { + type: TType; + payload: TPayload; + meta: TMeta; }; -export interface FluxStandardAction { - type: T; - payload: P; - meta: M; - error?: true; +export declare type EmptyAC = () => EmptyAction; +export declare type PayloadAC = (payload: TPayload) => PayloadAction; +export declare type PayloadMetaAC = (payload: TPayload, meta: TMeta) => PayloadMetaAction; +export interface TypeMeta { + getType?: () => TType; } -export declare type EmptyAC = () => EmptyAction; -export declare type PayloadAC = (payload: P) => PayloadAction; -export declare type PayloadMetaAC = (payload: P, meta: M) => PayloadMetaAction; -export declare type ActionBuilderConstructor = [TMeta] extends [undefined] ? [TPayload] extends [undefined] ? unknown extends TPayload ? PayloadAC : unknown extends TMeta ? PayloadMetaAC : EmptyAC : PayloadAC : PayloadMetaAC; -export declare type ActionBuilderMap = [TMetaArg] extends [undefined] ? [TPayloadArg] extends [undefined] ? () => { - type: T; -} & TCustomAction : (payload: TPayloadArg) => { - type: T; -} & TCustomAction : (payload: TPayloadArg, meta: TMetaArg) => { - type: T; -} & TCustomAction; +export declare type ActionType = TActionCreatorOrMap extends ActionCreator ? ReturnType : TActionCreatorOrMap extends Record ? { + [K in keyof TActionCreatorOrMap]: ActionType; +}[keyof TActionCreatorOrMap] : TActionCreatorOrMap extends infer R ? never : never; +export declare type StateType = TReducerOrMap extends Reducer ? ReturnType : TReducerOrMap extends Record ? { + [K in keyof TReducerOrMap]: StateType; +} : never; +export declare type ActionBuilderConstructor = [TMeta] extends [undefined] ? [TPayload] extends [undefined] ? unknown extends TPayload ? PayloadAC : unknown extends TMeta ? PayloadMetaAC : EmptyAC : PayloadAC : PayloadMetaAC; +export declare type ActionBuilderMap = [TMetaArg] extends [undefined] ? [TPayloadArg] extends [undefined] ? () => { + type: TType; +} & TActionProps : (payload: TPayloadArg) => { + type: TType; +} & TActionProps : (payload: TPayloadArg, meta: TMetaArg) => { + type: TType; +} & TActionProps; diff --git a/codesandbox/src/typesafe-actions/utils/validation.d.ts b/codesandbox/src/typesafe-actions/utils/validation.d.ts index 282adbd..f4811aa 100644 --- a/codesandbox/src/typesafe-actions/utils/validation.d.ts +++ b/codesandbox/src/typesafe-actions/utils/validation.d.ts @@ -1,12 +1,12 @@ -import { ActionCreator, TypeMeta, StringType } from '../type-helpers'; +import { ActionCreator, TypeMeta, TypeConstant } from '../type-helpers'; export declare function checkIsEmpty(arg: unknown, argPosition?: number): boolean; export declare function throwIsEmpty(argPosition?: number): never; -export declare function checkValidActionCreator(arg: unknown): arg is ActionCreator; +export declare function checkValidActionCreator(arg: unknown): arg is ActionCreator; export declare function checkInvalidActionCreator(arg: unknown): boolean; export declare function throwInvalidActionCreator(argPosition?: number): never; -export declare function checkInvalidActionCreatorInArray(arg: ActionCreator & TypeMeta, idx: number): void | never; +export declare function checkInvalidActionCreatorInArray(arg: ActionCreator & TypeMeta, idx: number): void | never; export declare function checkValidActionType(arg: unknown): arg is string | symbol; export declare function checkInvalidActionType(arg: unknown): arg is string | symbol; export declare function throwInvalidActionType(argPosition?: number): never; -export declare function checkInvalidActionTypeInArray(arg: StringType, idx: number): void | never; +export declare function checkInvalidActionTypeInArray(arg: TypeConstant, idx: number): void | never; export declare function throwInvalidActionTypeOrActionCreator(argPosition?: number): never;