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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions types/dom-navigation/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"@definitelytyped/no-type-only-packages": "off"
}
}
184 changes: 2 additions & 182 deletions types/dom-navigation/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,183 +1,3 @@
interface Window {
readonly navigation: Navigation;
}
// As of TS 6.0, the dom-navigation types are included in lib.dom.d.ts.

interface NavigationEventMap {
navigate: NavigateEvent;
navigatesuccess: Event;
navigateerror: ErrorEvent;
currententrychange: NavigationCurrentEntryChangeEvent;
}

interface NavigationResult {
committed: Promise<NavigationHistoryEntry>;
finished: Promise<NavigationHistoryEntry>;
}

declare class Navigation extends EventTarget {
entries(): NavigationHistoryEntry[];
readonly currentEntry: NavigationHistoryEntry | null;
updateCurrentEntry(options: NavigationUpdateCurrentEntryOptions): void;
readonly transition: NavigationTransition | null;

readonly canGoBack: boolean;
readonly canGoForward: boolean;

navigate(url: string, options?: NavigationNavigateOptions): NavigationResult;
reload(options?: NavigationReloadOptions): NavigationResult;

traverseTo(key: string, options?: NavigationOptions): NavigationResult;
back(options?: NavigationOptions): NavigationResult;
forward(options?: NavigationOptions): NavigationResult;

onnavigate: ((this: Navigation, ev: NavigateEvent) => any) | null;
onnavigatesuccess: ((this: Navigation, ev: Event) => any) | null;
onnavigateerror: ((this: Navigation, ev: ErrorEvent) => any) | null;
oncurrententrychange: ((this: Navigation, ev: NavigationCurrentEntryChangeEvent) => any) | null;

addEventListener<K extends keyof NavigationEventMap>(
type: K,
listener: (this: Navigation, ev: NavigationEventMap[K]) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
removeEventListener<K extends keyof NavigationEventMap>(
type: K,
listener: (this: Navigation, ev: NavigationEventMap[K]) => any,
options?: boolean | EventListenerOptions,
): void;
removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): void;
}

declare class NavigationTransition {
readonly navigationType: NavigationTypeString;
readonly from: NavigationHistoryEntry;
readonly finished: Promise<void>;
}

interface NavigationHistoryEntryEventMap {
dispose: Event;
}

interface NavigationHistoryEntry extends EventTarget {
readonly key: string;
readonly id: string;
readonly url: string | null;
readonly index: number;
readonly sameDocument: boolean;

getState(): unknown;

ondispose: ((this: NavigationHistoryEntry, ev: Event) => any) | null;

addEventListener<K extends keyof NavigationHistoryEntryEventMap>(
type: K,
listener: (this: NavigationHistoryEntry, ev: NavigationHistoryEntryEventMap[K]) => any,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions,
): void;
removeEventListener<K extends keyof NavigationHistoryEntryEventMap>(
type: K,
listener: (this: NavigationHistoryEntry, ev: NavigationHistoryEntryEventMap[K]) => any,
options?: boolean | EventListenerOptions,
): void;
removeEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | EventListenerOptions,
): void;
}

declare var NavigationHistoryEntry: {
prototype: NavigationHistoryEntry;
new(): NavigationHistoryEntry;
};

type NavigationTypeString = "reload" | "push" | "replace" | "traverse";

interface NavigationUpdateCurrentEntryOptions {
state: unknown;
}

interface NavigationOptions {
info?: unknown;
}

interface NavigationNavigateOptions extends NavigationOptions {
state?: unknown;
history?: "auto" | "push" | "replace";
}

interface NavigationReloadOptions extends NavigationOptions {
state?: unknown;
}

declare class NavigationCurrentEntryChangeEvent extends Event {
constructor(type: string, eventInit?: NavigationCurrentEntryChangeEventInit);

readonly navigationType: NavigationTypeString | null;
readonly from: NavigationHistoryEntry;
}

interface NavigationCurrentEntryChangeEventInit extends EventInit {
navigationType?: NavigationTypeString | null;
from: NavigationHistoryEntry;
}

declare class NavigateEvent extends Event {
constructor(type: string, eventInit?: NavigateEventInit);

readonly navigationType: NavigationTypeString;
readonly canIntercept: boolean;
readonly userInitiated: boolean;
readonly hashChange: boolean;
readonly hasUAVisualTransition: boolean;
readonly destination: NavigationDestination;
readonly signal: AbortSignal;
readonly formData: FormData | null;
readonly downloadRequest: string | null;
readonly info?: unknown;

intercept(options?: NavigationInterceptOptions): void;
scroll(): void;
}

interface NavigateEventInit extends EventInit {
navigationType?: NavigationTypeString;
canIntercept?: boolean;
userInitiated?: boolean;
hashChange?: boolean;
destination: NavigationDestination;
signal: AbortSignal;
formData?: FormData | null;
downloadRequest?: string | null;
info?: unknown;
}

interface NavigationInterceptOptions {
handler?: () => Promise<void>;
focusReset?: "after-transition" | "manual";
scroll?: "after-transition" | "manual";
}

declare class NavigationDestination {
readonly url: string;
readonly key: string | null;
readonly id: string | null;
readonly index: number;
readonly sameDocument: boolean;

getState(): unknown;
}
type NavigationTypeString = NavigationType;
8 changes: 8 additions & 0 deletions types/dom-navigation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
"projects": [
"https://wicg.github.io/navigation-api"
],
"types": "index",
"typesVersions": {
"<=5.9": {
"*": [
"ts5.9/*"
]
}
},
"devDependencies": {
"@types/dom-navigation": "workspace:."
},
Expand Down
66 changes: 66 additions & 0 deletions types/dom-navigation/ts5.9/dom-navigation-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const navigation = window.navigation;

const entries: NavigationHistoryEntry[] = navigation.entries();
const entry: NavigationHistoryEntry | null = navigation.currentEntry;
if (entry) {
const key: string = entry.key;
const id: string = entry.id;
const url: string | null = entry.url;
const index: number = entry.index;
const sameDocument: boolean = entry.sameDocument;
const state: unknown = entry.getState();
entry.ondispose = () => {};
const listener = () => {};
entry.addEventListener("dispose", listener);
entry.removeEventListener("dispose", listener);
}
navigation.updateCurrentEntry({ state: "" as unknown });
const transition: NavigationTransition | null = navigation.transition;
if (transition) {
const navigationType: NavigationTypeString = transition.navigationType;
const from: NavigationHistoryEntry = transition.from;
const finished: Promise<void> = transition.finished;
}
const canGoBack: boolean = navigation.canGoBack;
const canGoForward: boolean = navigation.canGoForward;
navigation.navigate("/url", { state: "" as unknown, history: "replace", info: "" as unknown });
navigation.reload({ state: "" as unknown, info: "" as unknown });
navigation.traverseTo("", { info: "" as unknown });
navigation.back({ info: "" as unknown });
navigation.forward({ info: "" as unknown });
const navigateListener = (e: NavigateEvent) => {
const navigationType: NavigationTypeString = e.navigationType;
const canIntercept: boolean = e.canIntercept;
const userInitiated: boolean = e.userInitiated;
const hashChange: boolean = e.hashChange;
const hasUAVisualTransition: boolean = e.hasUAVisualTransition;
const destination: NavigationDestination = e.destination;
const url: string = destination.url;
const key: string | null = destination.key;
const id: string | null = destination.id;
const index: number = destination.index;
const sameDocument: boolean = destination.sameDocument;
const state: unknown = destination.getState();
const signal: AbortSignal = e.signal;
const formData: FormData | null = e.formData;
const downloadRequest: string | null = e.downloadRequest;
const info: unknown = e.info;
};
navigation.onnavigate = navigateListener;
navigation.addEventListener("navigate", navigateListener);
navigation.removeEventListener("navigate", navigateListener);
const navigateSuccessListener = (e: Event) => {};
navigation.onnavigatesuccess = navigateSuccessListener;
navigation.addEventListener("navigatesuccess", navigateSuccessListener);
navigation.removeEventListener("navigatesuccess", navigateSuccessListener);
const navigateErrorListener = (e: Event) => {};
navigation.onnavigateerror = navigateErrorListener;
navigation.addEventListener("navigateerror", navigateErrorListener);
navigation.removeEventListener("navigateerror", navigateErrorListener);
const currentEntryChangeListener = (e: NavigationCurrentEntryChangeEvent) => {
const navigationType: NavigationTypeString | null = e.navigationType;
const from: NavigationHistoryEntry = e.from;
};
navigation.oncurrententrychange = currentEntryChangeListener;
navigation.addEventListener("currententrychange", currentEntryChangeListener);
navigation.removeEventListener("currententrychange", currentEntryChangeListener);
Loading