Skip to content
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
29 changes: 21 additions & 8 deletions types/history/v3/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Project: https://github.com/mjackson/history
// Definitions by: Sergey Buturlakin <https://github.com/sergey-buturlakin>, Nathan Brown <https://github.com/ngbrown>, Karol Janyst <https://github.com/LKay>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

export as namespace History;

Expand All @@ -10,10 +11,10 @@ export type BeforeUnloadHook = () => string | boolean;
export type CreateHistory<O, H> = (options?: HistoryOptions & O) => History & H;
export type CreateHistoryEnhancer<O, H, E> = (createHistory: CreateHistory<O, H>) => CreateHistory<O, H & E>;

export interface History {
export interface History<Q = DefaultQuery, QL = DefaultQueryLike> {
listenBefore(hook: TransitionHook): () => void;
listen(listener: LocationListener): () => void;
transitionTo(location: Location): void;
transitionTo(location: Location<Q>): void;
push(path: LocationDescriptor): void;
replace(path: LocationDescriptor): void;
go(n: number): void;
Expand All @@ -22,8 +23,8 @@ export interface History {
createKey(): LocationKey;
createPath(path: LocationDescriptor): Path;
createHref(path: LocationDescriptor): Href;
createLocation(path?: LocationDescriptor, action?: Action, key?: LocationKey): Location;
getCurrentLocation(): Location;
createLocation(path?: LocationDescriptor, action?: Action, key?: LocationKey): Location<Q>;
getCurrentLocation(): Location<Q>;
}

export interface HistoryOptions {
Expand All @@ -34,10 +35,10 @@ export interface HistoryOptions {
export type Hash = string;
export type Href = string;

export interface Location {
export interface Location<Q = DefaultQuery> {
pathname: Pathname;
search: Search;
query: Query;
query: Query<Q>;
hash: Hash;
state: LocationState;
action: Action;
Expand All @@ -47,7 +48,7 @@ export interface Location {
export interface LocationDescriptorObject {
pathname?: Pathname;
search?: Search;
query?: Query;
query?: QueryLike;
hash?: Hash;
state?: LocationState;
}
Expand All @@ -62,7 +63,19 @@ export type LocationState = any;

export type Path = string; // Pathname + Search;
export type Pathname = string;
export type Query = any;

type DefaultQuery<T = string> = {
[key: string]: T | T[] | null | undefined;
};

type DefaultQueryLike = {
[key: string]: any;
};

export type Query<T = DefaultQuery> = T;

type QueryLike<T = DefaultQueryLike> = T;

export type Search = string;

export type TransitionHook = (location: Location, callback: (result: any) => void) => any;
Expand Down
2 changes: 1 addition & 1 deletion types/react-router-redux/v3/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Project: https://github.com/rackt/react-router-redux
// Definitions by: Isman Usoh <https://github.com/isman-usoh>, Noah Shipley <https://github.com/noah79>, Dimitri Rosenberg <https://github.com/rosendi>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
// TypeScript Version: 2.3

import * as Redux from "redux";
import * as History from "history";
Expand Down
2 changes: 1 addition & 1 deletion types/react-router-redux/v4/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Karol Janyst <https://github.com/LKay>,
// Dovydas Navickas <https://github.com/DovydasNavickas>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
// TypeScript Version: 2.3

import { Action, Middleware, Store } from "redux";
import { History, Location, LocationDescriptor } from "history";
Expand Down