-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
674c087
commit 1fd50de
Showing
14 changed files
with
85 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
import { StringType } from './type-helpers'; | ||
export declare function action<T extends StringType, E>(type: T, payload: undefined, meta: undefined, error: E): { | ||
import { TypeConstant } from './type-helpers'; | ||
export declare function action<T extends TypeConstant, E>(type: T, payload: undefined, meta: undefined, error: E): { | ||
type: T; | ||
error: E; | ||
}; | ||
export declare function action<T extends StringType, M, E>(type: T, payload: undefined, meta: M, error: E): { | ||
export declare function action<T extends TypeConstant, M, E>(type: T, payload: undefined, meta: M, error: E): { | ||
type: T; | ||
meta: M; | ||
error: E; | ||
}; | ||
export declare function action<T extends StringType, P, E>(type: T, payload: P, meta: undefined, error: E): { | ||
export declare function action<T extends TypeConstant, P, E>(type: T, payload: P, meta: undefined, error: E): { | ||
type: T; | ||
payload: P; | ||
error: E; | ||
}; | ||
export declare function action<T extends StringType, P, M, E>(type: T, payload: P, meta: M, error: E): { | ||
export declare function action<T extends TypeConstant, P, M, E>(type: T, payload: P, meta: M, error: E): { | ||
type: T; | ||
payload: P; | ||
meta: M; | ||
error: E; | ||
}; | ||
export declare function action<T extends StringType, M>(type: T, payload: undefined, meta: M): { | ||
export declare function action<T extends TypeConstant, M>(type: T, payload: undefined, meta: M): { | ||
type: T; | ||
meta: M; | ||
}; | ||
export declare function action<T extends StringType, P, M>(type: T, payload: P, meta: M): { | ||
export declare function action<T extends TypeConstant, P, M>(type: T, payload: P, meta: M): { | ||
type: T; | ||
payload: P; | ||
meta: M; | ||
}; | ||
export declare function action<T extends StringType, P>(type: T, payload: P): { | ||
export declare function action<T extends TypeConstant, P>(type: T, payload: P): { | ||
type: T; | ||
payload: P; | ||
}; | ||
export declare function action<T extends StringType>(type: T): { | ||
export declare function action<T extends TypeConstant>(type: T): { | ||
type: T; | ||
}; |
8 changes: 4 additions & 4 deletions
8
codesandbox/src/typesafe-actions/create-action-deprecated.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { StringType } from './type-helpers'; | ||
interface FSA<T extends StringType, P = {}, M = {}, E = boolean> { | ||
import { TypeConstant } from './type-helpers'; | ||
interface FSA<T extends TypeConstant, P = {}, M = {}, E = boolean> { | ||
type: T; | ||
payload?: P; | ||
meta?: M; | ||
error?: E; | ||
} | ||
export declare function createActionDeprecated<T extends StringType, AC extends (...args: any[]) => FSA<T>>(actionType: T, creatorFunction: AC): AC; | ||
export declare function createActionDeprecated<T extends StringType, AC extends () => { | ||
export declare function createActionDeprecated<T extends TypeConstant, AC extends (...args: any[]) => FSA<T>>(actionType: T, creatorFunction: AC): AC; | ||
export declare function createActionDeprecated<T extends TypeConstant, AC extends () => { | ||
type: T; | ||
}>(actionType: T): AC; | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { StringType, ActionBuilderConstructor } from './type-helpers'; | ||
export interface AsyncActionBuilder<T1 extends StringType, T2 extends StringType, T3 extends StringType> { | ||
import { TypeConstant, ActionBuilderConstructor } from './type-helpers'; | ||
export interface AsyncActionBuilder<T1 extends TypeConstant, T2 extends TypeConstant, T3 extends TypeConstant> { | ||
<P1, P2, P3>(): AsyncActionBuilderConstructor<T1, T2, T3, P1, P2, P3>; | ||
} | ||
export declare type AsyncActionBuilderConstructor<T1 extends StringType, T2 extends StringType, T3 extends StringType, P1, P2, P3> = { | ||
export declare type AsyncActionBuilderConstructor<T1 extends TypeConstant, T2 extends TypeConstant, T3 extends TypeConstant, P1, P2, P3> = { | ||
request: ActionBuilderConstructor<T1, P1>; | ||
success: ActionBuilderConstructor<T2, P2>; | ||
failure: ActionBuilderConstructor<T3, P3>; | ||
}; | ||
export declare function createAsyncAction<T1 extends StringType, T2 extends StringType, T3 extends StringType>(requestType: T1, successType: T2, failureType: T3): AsyncActionBuilder<T1, T2, T3>; | ||
export declare function createAsyncAction<T1 extends TypeConstant, T2 extends TypeConstant, T3 extends TypeConstant>(requestType: T1, successType: T2, failureType: T3): AsyncActionBuilder<T1, T2, T3>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { ActionCreator, StringType } from './type-helpers'; | ||
export declare function createCustomAction<T extends StringType, AC extends ActionCreator<T> = () => { | ||
import { ActionCreator, TypeConstant } from './type-helpers'; | ||
export declare function createCustomAction<T extends TypeConstant, AC extends ActionCreator<T> = () => { | ||
type: T; | ||
}>(type: T, createHandler?: (type: T) => AC): AC; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { StringType, ActionBuilderConstructor, ActionBuilderMap } from './type-helpers'; | ||
export interface ActionBuilder<T extends StringType> { | ||
import { TypeConstant, ActionBuilderConstructor, ActionBuilderMap } from './type-helpers'; | ||
export interface ActionBuilder<T extends TypeConstant> { | ||
<P = undefined, M = undefined>(): ActionBuilderConstructor<T, P, M>; | ||
map<R, P = undefined, M = undefined>(fn: (payload: P, meta: M) => R): ActionBuilderMap<T, R, P, M>; | ||
} | ||
export declare function createStandardAction<T extends StringType>(type: T): ActionBuilder<T>; | ||
export declare function createStandardAction<T extends TypeConstant>(type: T): ActionBuilder<T>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
import { StringType, ActionCreator, TypeMeta } from './type-helpers'; | ||
export declare function getType<T extends StringType>(actionCreator: ActionCreator<T> & TypeMeta<T>): T; | ||
import { TypeConstant, ActionCreator, TypeMeta } from './type-helpers'; | ||
export declare function getType<T extends TypeConstant>(actionCreator: ActionCreator<T> & TypeMeta<T>): T; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,42 @@ | ||
export interface TypeMeta<T extends StringType> { | ||
getType?: () => T; | ||
} | ||
export declare type ActionCreator<T extends StringType> = (...args: any[]) => { | ||
type: T; | ||
export declare type TypeConstant = string; | ||
export declare type Action<TType extends TypeConstant = TypeConstant> = { | ||
type: TType; | ||
}; | ||
export declare type ActionType<ActionCreatorOrMap extends any> = ActionCreatorOrMap extends ActionCreator<string> ? ReturnType<ActionCreatorOrMap> : ActionCreatorOrMap extends Record<any, any> ? { | ||
[K in keyof ActionCreatorOrMap]: ActionType<ActionCreatorOrMap[K]>; | ||
}[keyof ActionCreatorOrMap] : ActionCreatorOrMap extends infer R ? never : never; | ||
export declare type StateType<ReducerOrMap> = ReducerOrMap extends (...args: any[]) => any ? ReturnType<ReducerOrMap> : ReducerOrMap extends object ? { | ||
[K in keyof ReducerOrMap]: StateType<ReducerOrMap[K]>; | ||
} : never; | ||
export declare type StringType = string; | ||
export declare type EmptyAction<T extends StringType> = { | ||
type: T; | ||
export declare type ActionCreator<TType extends TypeConstant> = (...args: any[]) => Action<TType>; | ||
export declare type Reducer<TState, TAction extends Action> = (state: TState | undefined, action: TAction) => TState; | ||
export declare type EmptyAction<TType extends TypeConstant> = { | ||
type: TType; | ||
}; | ||
export declare type PayloadAction<T extends StringType, P> = { | ||
type: T; | ||
payload: P; | ||
export declare type PayloadAction<TType extends TypeConstant, TPayload> = { | ||
type: TType; | ||
payload: TPayload; | ||
}; | ||
export declare type MetaAction<T extends StringType, M> = { | ||
type: T; | ||
meta: M; | ||
export declare type MetaAction<TType extends TypeConstant, TMeta> = { | ||
type: TType; | ||
meta: TMeta; | ||
}; | ||
export declare type PayloadMetaAction<T extends StringType, P, M> = { | ||
type: T; | ||
payload: P; | ||
meta: M; | ||
export declare type PayloadMetaAction<TType extends TypeConstant, TPayload, TMeta> = { | ||
type: TType; | ||
payload: TPayload; | ||
meta: TMeta; | ||
}; | ||
export interface FluxStandardAction<T extends StringType, P = undefined, M = undefined> { | ||
type: T; | ||
payload: P; | ||
meta: M; | ||
error?: true; | ||
export declare type EmptyAC<TType extends TypeConstant> = () => EmptyAction<TType>; | ||
export declare type PayloadAC<TType extends TypeConstant, TPayload> = (payload: TPayload) => PayloadAction<TType, TPayload>; | ||
export declare type PayloadMetaAC<TType extends TypeConstant, TPayload, TMeta> = (payload: TPayload, meta: TMeta) => PayloadMetaAction<TType, TPayload, TMeta>; | ||
export interface TypeMeta<TType extends TypeConstant> { | ||
getType?: () => TType; | ||
} | ||
export declare type EmptyAC<T extends StringType> = () => EmptyAction<T>; | ||
export declare type PayloadAC<T extends StringType, P> = (payload: P) => PayloadAction<T, P>; | ||
export declare type PayloadMetaAC<T extends StringType, P, M> = (payload: P, meta: M) => PayloadMetaAction<T, P, M>; | ||
export declare type ActionBuilderConstructor<T extends StringType, TPayload extends any = undefined, TMeta extends any = undefined> = [TMeta] extends [undefined] ? [TPayload] extends [undefined] ? unknown extends TPayload ? PayloadAC<T, TPayload> : unknown extends TMeta ? PayloadMetaAC<T, TPayload, TMeta> : EmptyAC<T> : PayloadAC<T, TPayload> : PayloadMetaAC<T, TPayload, TMeta>; | ||
export declare type ActionBuilderMap<T extends StringType, TCustomAction extends any, TPayloadArg extends any = undefined, TMetaArg extends any = undefined> = [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 any> = TActionCreatorOrMap extends ActionCreator<TypeConstant> ? ReturnType<TActionCreatorOrMap> : TActionCreatorOrMap extends Record<any, any> ? { | ||
[K in keyof TActionCreatorOrMap]: ActionType<TActionCreatorOrMap[K]>; | ||
}[keyof TActionCreatorOrMap] : TActionCreatorOrMap extends infer R ? never : never; | ||
export declare type StateType<TReducerOrMap extends any> = TReducerOrMap extends Reducer<any, any> ? ReturnType<TReducerOrMap> : TReducerOrMap extends Record<any, any> ? { | ||
[K in keyof TReducerOrMap]: StateType<TReducerOrMap[K]>; | ||
} : never; | ||
export declare type ActionBuilderConstructor<TType extends TypeConstant, TPayload extends any = undefined, TMeta extends any = undefined> = [TMeta] extends [undefined] ? [TPayload] extends [undefined] ? unknown extends TPayload ? PayloadAC<TType, TPayload> : unknown extends TMeta ? PayloadMetaAC<TType, TPayload, TMeta> : EmptyAC<TType> : PayloadAC<TType, TPayload> : PayloadMetaAC<TType, TPayload, TMeta>; | ||
export declare type ActionBuilderMap<TType extends TypeConstant, TActionProps extends any, TPayloadArg extends any = undefined, TMetaArg extends any = undefined> = [TMetaArg] extends [undefined] ? [TPayloadArg] extends [undefined] ? () => { | ||
type: TType; | ||
} & TActionProps : (payload: TPayloadArg) => { | ||
type: TType; | ||
} & TActionProps : (payload: TPayloadArg, meta: TMetaArg) => { | ||
type: TType; | ||
} & TActionProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<StringType>; | ||
export declare function checkValidActionCreator(arg: unknown): arg is ActionCreator<TypeConstant>; | ||
export declare function checkInvalidActionCreator(arg: unknown): boolean; | ||
export declare function throwInvalidActionCreator(argPosition?: number): never; | ||
export declare function checkInvalidActionCreatorInArray(arg: ActionCreator<StringType> & TypeMeta<StringType>, idx: number): void | never; | ||
export declare function checkInvalidActionCreatorInArray(arg: ActionCreator<TypeConstant> & TypeMeta<TypeConstant>, 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; |