Skip to content

Commit

Permalink
fix: export more types
Browse files Browse the repository at this point in the history
Closes #137
  • Loading branch information
posva committed Mar 23, 2020
1 parent da10b40 commit 1583d48
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/history/common.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ListenerRemover } from '../types'
import { LocationQueryRaw, LocationQuery } from '../utils/query'

interface HistoryLocation {
Expand Down Expand Up @@ -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
}

Expand Down
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 1 addition & 5 deletions src/matcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
RouteRecord,
MatcherLocation,
MatcherLocationNormalized,
ListenerRemover,
} from '../types'
import { createRouterError, ErrorTypes, MatcherError } from '../errors'
import { createRouteRecordMatcher, RouteRecordMatcher } from './path-matcher'
Expand All @@ -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<RouteRecord>['name']): void
Expand Down
13 changes: 8 additions & 5 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
RouteRecord,
RouteLocation,
NavigationGuard,
ListenerRemover,
PostNavigationGuard,
START_LOCATION_NORMALIZED,
Lazy,
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -75,10 +78,10 @@ export interface Router {
push(to: RouteLocation): Promise<RouteLocationNormalizedResolved>
replace(to: RouteLocation): Promise<RouteLocationNormalizedResolved>

beforeEach(guard: NavigationGuard<undefined>): ListenerRemover
afterEach(guard: PostNavigationGuard): ListenerRemover
beforeEach(guard: NavigationGuard<undefined>): () => void
afterEach(guard: PostNavigationGuard): () => void

onError(handler: ErrorHandler): ListenerRemover
onError(handler: ErrorHandler): () => void
isReady(): Promise<void>

install(app: App): void
Expand Down
4 changes: 1 addition & 3 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export type Immutable<T> = {

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
Expand All @@ -38,7 +36,7 @@ export interface LocationAsName {
}

export interface LocationAsRelative {
params?: RouteParams
params?: RouteParamsRaw
}

export interface RouteLocationOptions {
Expand Down

0 comments on commit 1583d48

Please sign in to comment.