Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve Redux-related types #351

Merged
merged 1 commit into from
Aug 2, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion types/Actions.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// TypeScript Version: 3.0

export { Actions as default } from 'farce';
export {
Actions as default,
Action,
DisposeAction,
GoAction,
InitAction,
PushAction,
ReplaceAction,
} from 'farce';
49 changes: 32 additions & 17 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,27 +151,42 @@ export const ActionTypes: {
DISPOSE: '@@farce/DISPOSE';
};

interface Action<TAction extends keyof typeof ActionTypes> {
type: typeof ActionTypes[TAction];
export interface InitAction {
type: typeof ActionTypes['INIT'];
}

interface ActionWithPayload<
TAction extends keyof typeof ActionTypes,
TPayload
> extends Action<TAction> {
payload: TPayload;
export interface PushAction {
type: typeof ActionTypes['PUSH'];
payload: LocationDescriptor;
}

export interface ReplaceAction {
type: typeof ActionTypes['REPLACE'];
payload: LocationDescriptor;
}

export interface GoAction {
type: typeof ActionTypes['GO'];
payload: number;
}

export interface DisposeAction {
type: typeof ActionTypes['DISPOSE'];
}

export type Action =
| InitAction
| PushAction
| ReplaceAction
| GoAction
| DisposeAction;

export const Actions: {
init(): Action<'INIT'>;
push(
location: LocationDescriptor,
): ActionWithPayload<'PUSH', LocationDescriptor>;
replace(
location: LocationDescriptor,
): ActionWithPayload<'REPLACE', LocationDescriptor>;
go(delta: number): ActionWithPayload<'GO', number>;
dispose(): Action<'DISPOSE'>;
init(): InitAction;
push(location: LocationDescriptor): PushAction;
replace(location: LocationDescriptor): ReplaceAction;
go(delta: number): GoAction;
dispose(): DisposeAction;
};

export interface Protocol {
Expand Down Expand Up @@ -237,7 +252,7 @@ export function createBasenameMiddleware(
options: BasenameMiddlewareOptions,
): Middleware;

export const locationReducer: Reducer<Location>;
export const locationReducer: Reducer<Location, Action>;

export class StateStorage {
constructor(farce: FarceStoreExtension, namespace: string);
Expand Down