Skip to content

Commit

Permalink
fix(types): add missing exported types
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Dec 24, 2020
1 parent c88e6db commit 034c71c
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/RouterLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface RouterLinkProps extends RouterLinkOptions {
| 'false'
}

type UseLinkOptions = VueUseOptions<RouterLinkOptions>
export type UseLinkOptions = VueUseOptions<RouterLinkOptions>

// TODO: we could allow currentRoute as a prop to expose `isActive` and
// `isExactActive` behavior should go through an RFC
Expand Down
6 changes: 6 additions & 0 deletions src/history/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -13,6 +16,9 @@ type HistoryStateValue =
| HistoryState
| HistoryStateArray

/**
* Allowed HTML history.state
*/
export interface HistoryState {
[x: number]: HistoryStateValue
[x: string]: HistoryStateValue
Expand Down
30 changes: 23 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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'

Expand All @@ -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'

Expand All @@ -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'
Expand Down
5 changes: 5 additions & 0 deletions src/matcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 3 additions & 3 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -978,7 +978,7 @@ export function createRouter(options: RouterOptions): Router {
// Initialization and Errors

let readyHandlers = useCallbacks<OnReadyCallback>()
let errorHandlers = useCallbacks<ErrorHandler>()
let errorHandlers = useCallbacks<_ErrorHandler>()
let ready: boolean

/**
Expand Down
34 changes: 33 additions & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,42 @@ export type Immutable<T> = {
readonly [P in keyof T]: Immutable<T[P]>
}

/**
* Type to transform a static object into one that allows passing Refs as
* values.
* @internal
*/
export type VueUseOptions<T> = {
[k in keyof T]: Ref<T[k]> | T[k] | ComputedRef<T[k]>
}

export type TODO = any

/**
* @internal
*/
export type RouteParamValue = string
/**
* @internal
*/
export type RouteParamValueRaw = RouteParamValue | number
export type RouteParams = Record<string, RouteParamValue | RouteParamValue[]>
export type RouteParamsRaw = Record<
string,
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
}
Expand All @@ -41,6 +58,9 @@ export interface LocationAsName {
params?: RouteParams
}

/**
* @internal
*/
export interface LocationAsRelativeRaw {
name?: RouteRecordName
params?: RouteParamsRaw
Expand Down Expand Up @@ -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<RouteComponent>

/**
* Possible values for a user-defined route record's name
*/
export type RouteRecordName = string | symbol

/**
Expand Down Expand Up @@ -221,6 +250,9 @@ export interface _RouteRecordBase extends PathParserOptions {
*/
export interface RouteMeta extends Record<string | number | symbol, any> {}

/**
* @internal
*/
export type RouteRecordRedirectOption =
| RouteLocationRaw
| ((to: RouteLocation) => RouteLocationRaw)
Expand Down

0 comments on commit 034c71c

Please sign in to comment.