From: Eduardo San Martin Morote Date: Mon, 23 Mar 2020 09:55:16 +0000 (+0100) Subject: fix: export more types X-Git-Tag: v4.0.0-alpha.4~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1583d480fff2da1caa35c2dd7892c36b57dad734;p=thirdparty%2Fvuejs%2Frouter.git fix: export more types Closes #137 --- diff --git a/src/history/common.ts b/src/history/common.ts index a59b9dd7..2269e9b8 100644 --- a/src/history/common.ts +++ b/src/history/common.ts @@ -1,4 +1,3 @@ -import { ListenerRemover } from '../types' import { LocationQueryRaw, LocationQuery } from '../utils/query' interface HistoryLocation { @@ -81,7 +80,7 @@ export interface RouterHistory { forward(triggerListeners?: boolean): void go(distance: number, triggerListeners?: boolean): void - listen(callback: NavigationCallback): ListenerRemover + listen(callback: NavigationCallback): () => void destroy(): void } diff --git a/src/index.ts b/src/index.ts index 8dbeb57e..e7e450e4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,14 +4,23 @@ import createWebHashHistory from './history/hash' import { inject } from 'vue' import { routerKey, routeLocationKey } from './utils/injectionSymbols' +export { LocationQuery, parseQuery, stringifyQuery } from './utils/query' + export { RouterHistory } from './history/common' +export { RouteRecordNormalized } from './matcher/types' + export { RouteLocationNormalized, - RouteLocationOptions, + RouteLocationNormalizedResolved, START_LOCATION_NORMALIZED as START_LOCATION, + RouteParams, + RouteLocationOptions, + RouteRecord, + NavigationGuard, + PostNavigationGuard, } from './types' -export { createRouter, Router, RouterOptions } from './router' +export { createRouter, Router, RouterOptions, ErrorHandler } from './router' export { onBeforeRouteLeave } from './navigationGuards' export { Link } from './components/Link' diff --git a/src/matcher/index.ts b/src/matcher/index.ts index 1f4e9d65..9019df83 100644 --- a/src/matcher/index.ts +++ b/src/matcher/index.ts @@ -2,7 +2,6 @@ import { RouteRecord, MatcherLocation, MatcherLocationNormalized, - ListenerRemover, } from '../types' import { createRouterError, ErrorTypes, MatcherError } from '../errors' import { createRouteRecordMatcher, RouteRecordMatcher } from './path-matcher' @@ -16,10 +15,7 @@ import { let noop = () => {} interface RouterMatcher { - addRoute: ( - record: RouteRecord, - parent?: RouteRecordMatcher - ) => ListenerRemover + addRoute: (record: RouteRecord, parent?: RouteRecordMatcher) => () => void removeRoute: { (matcher: RouteRecordMatcher): void (name: Required['name']): void diff --git a/src/router.ts b/src/router.ts index 5c71d773..161561cb 100644 --- a/src/router.ts +++ b/src/router.ts @@ -3,7 +3,6 @@ import { RouteRecord, RouteLocation, NavigationGuard, - ListenerRemover, PostNavigationGuard, START_LOCATION_NORMALIZED, Lazy, @@ -40,7 +39,11 @@ import { Link } from './components/Link' import { View } from './components/View' import { routerKey, routeLocationKey } from './utils/injectionSymbols' -type ErrorHandler = (error: any) => any +/** + * Internal type to define an ErrorHandler + * @internal + */ +export type ErrorHandler = (error: any) => any // resolve, reject arguments of Promise constructor type OnReadyCallback = [() => void, (reason?: any) => void] @@ -75,10 +78,10 @@ export interface Router { push(to: RouteLocation): Promise replace(to: RouteLocation): Promise - beforeEach(guard: NavigationGuard): ListenerRemover - afterEach(guard: PostNavigationGuard): ListenerRemover + beforeEach(guard: NavigationGuard): () => void + afterEach(guard: PostNavigationGuard): () => void - onError(handler: ErrorHandler): ListenerRemover + onError(handler: ErrorHandler): () => void isReady(): Promise install(app: App): void diff --git a/src/types/index.ts b/src/types/index.ts index 12c3f595..2e49b347 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -12,8 +12,6 @@ export type Immutable = { export type TODO = any -export type ListenerRemover = () => void - export type RouteParamValue = string // TODO: should we allow more values like numbers and normalize them to strings? // type RouteParamValueRaw = RouteParamValue | number @@ -38,7 +36,7 @@ export interface LocationAsName { } export interface LocationAsRelative { - params?: RouteParams + params?: RouteParamsRaw } export interface RouteLocationOptions {