From: Eduardo San Martin Morote Date: Thu, 24 Dec 2020 09:45:29 +0000 (+0100) Subject: fix(types): add missing exported types X-Git-Tag: v4.0.2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=034c71c72ca46d242daf53ae54ab67e6f7800f91;p=thirdparty%2Fvuejs%2Frouter.git fix(types): add missing exported types --- diff --git a/src/RouterLink.ts b/src/RouterLink.ts index da874c78..8be402f5 100644 --- a/src/RouterLink.ts +++ b/src/RouterLink.ts @@ -56,7 +56,7 @@ export interface RouterLinkProps extends RouterLinkOptions { | 'false' } -type UseLinkOptions = VueUseOptions +export type UseLinkOptions = VueUseOptions // TODO: we could allow currentRoute as a prop to expose `isActive` and // `isExactActive` behavior should go through an RFC diff --git a/src/history/common.ts b/src/history/common.ts index 3dc320fb..b203f17b 100644 --- a/src/history/common.ts +++ b/src/history/common.ts @@ -4,6 +4,9 @@ import { removeTrailingSlash } from '../location' export type HistoryLocation = string // pushState clones the state passed and do not accept everything // it doesn't accept symbols, nor functions as values. It also ignores Symbols as keys +/** + * Allowed variables in HTML5 history state + */ type HistoryStateValue = | string | number @@ -13,6 +16,9 @@ type HistoryStateValue = | HistoryState | HistoryStateArray +/** + * Allowed HTML history.state + */ export interface HistoryState { [x: number]: HistoryStateValue [x: string]: HistoryStateValue diff --git a/src/index.ts b/src/index.ts index 8ace025d..370bf170 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ export { createWebHistory } from './history/html5' export { createMemoryHistory } from './history/memory' export { createWebHashHistory } from './history/hash' -export { createRouterMatcher } from './matcher' +export { createRouterMatcher, RouterMatcher } from './matcher' export { LocationQuery, @@ -12,7 +12,7 @@ export { LocationQueryValueRaw, } from './query' -export { RouterHistory } from './history/common' +export { RouterHistory, HistoryState } from './history/common' export { RouteRecord, RouteRecordNormalized } from './matcher/types' @@ -30,27 +30,38 @@ export { } from './injectionSymbols' export { - RouteMeta, + // route location _RouteLocationBase, - _RouteRecordBase, + LocationAsPath, + LocationAsRelativeRaw, + RouteQueryAndHash, RouteLocationRaw, RouteLocation, RouteLocationNormalized, RouteLocationNormalizedLoaded, - START_LOCATION_NORMALIZED as START_LOCATION, RouteParams, + RouteParamValue, RouteLocationMatched, RouteLocationOptions, + RouteRecordRedirectOption, + // route records + _RouteRecordBase, + RouteMeta, + START_LOCATION_NORMALIZED as START_LOCATION, + RouteComponent, + // RawRouteComponent, + RouteRecordName, RouteRecordRaw, NavigationGuard, NavigationGuardNext, + NavigationGuardWithThis, NavigationHookAfter, } from './types' + export { createRouter, Router, RouterOptions, - ErrorHandler, RouterScrollBehavior, } from './router' @@ -61,7 +72,12 @@ export { } from './errors' export { onBeforeRouteLeave, onBeforeRouteUpdate } from './navigationGuards' -export { RouterLink, useLink, RouterLinkProps } from './RouterLink' +export { + RouterLink, + useLink, + RouterLinkProps, + UseLinkOptions, +} from './RouterLink' export { RouterView, RouterViewProps } from './RouterView' export * from './useApi' diff --git a/src/matcher/index.ts b/src/matcher/index.ts index dd5aa024..2b2a0a56 100644 --- a/src/matcher/index.ts +++ b/src/matcher/index.ts @@ -18,6 +18,11 @@ import { import { warn } from '../warning' import { assign, noop } from '../utils' +/** + * Internal RouterMatcher + * + * @internal + */ export interface RouterMatcher { addRoute: (record: RouteRecordRaw, parent?: RouteRecordMatcher) => () => void removeRoute: { diff --git a/src/router.ts b/src/router.ts index 6cf8531f..8561d257 100644 --- a/src/router.ts +++ b/src/router.ts @@ -67,7 +67,7 @@ import { addDevtools } from './devtools' * Internal type to define an ErrorHandler * @internal */ -export type ErrorHandler = (error: any) => any +export type _ErrorHandler = (error: any) => any // resolve, reject arguments of Promise constructor type OnReadyCallback = [() => void, (reason?: any) => void] @@ -304,7 +304,7 @@ export interface Router { * * @param handler - error handler to register */ - onError(handler: ErrorHandler): () => void + onError(handler: _ErrorHandler): () => void /** * Returns a Promise that resolves when the router has completed the initial * navigation, which means it has resolved all async enter hooks and async @@ -978,7 +978,7 @@ export function createRouter(options: RouterOptions): Router { // Initialization and Errors let readyHandlers = useCallbacks() - let errorHandlers = useCallbacks() + let errorHandlers = useCallbacks<_ErrorHandler>() let ready: boolean /** diff --git a/src/types/index.ts b/src/types/index.ts index b3a58214..26032a7b 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -13,13 +13,24 @@ export type Immutable = { readonly [P in keyof T]: Immutable } +/** + * Type to transform a static object into one that allows passing Refs as + * values. + * @internal + */ export type VueUseOptions = { [k in keyof T]: Ref | T[k] | ComputedRef } export type TODO = any +/** + * @internal + */ export type RouteParamValue = string +/** + * @internal + */ export type RouteParamValueRaw = RouteParamValue | number export type RouteParams = Record export type RouteParamsRaw = Record< @@ -27,11 +38,17 @@ export type RouteParamsRaw = Record< RouteParamValueRaw | RouteParamValueRaw[] > -// TODO: document, mark as internal and export intermediate types for RouteLocationRaw +/** + * @internal + */ export interface RouteQueryAndHash { query?: LocationQueryRaw hash?: string } + +/** + * @internal + */ export interface LocationAsPath { path: string } @@ -41,6 +58,9 @@ export interface LocationAsName { params?: RouteParams } +/** + * @internal + */ export interface LocationAsRelativeRaw { name?: RouteRecordName params?: RouteParamsRaw @@ -157,9 +177,18 @@ export interface RouteLocationNormalized extends _RouteLocationBase { matched: RouteRecordNormalized[] // non-enumerable } +/** + * Allowed Component in {@link RouteLocationMatched} + */ export type RouteComponent = Component +/** + * Allowed Component definitions in route records provided by the user + */ export type RawRouteComponent = RouteComponent | Lazy +/** + * Possible values for a user-defined route record's name + */ export type RouteRecordName = string | symbol /** @@ -221,6 +250,9 @@ export interface _RouteRecordBase extends PathParserOptions { */ export interface RouteMeta extends Record {} +/** + * @internal + */ export type RouteRecordRedirectOption = | RouteLocationRaw | ((to: RouteLocation) => RouteLocationRaw)