Skip to content

Commit

Permalink
docs: more ts doc
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Sep 10, 2020
1 parent 9fc0996 commit 889f86c
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 67 deletions.
3 changes: 3 additions & 0 deletions src/RouterLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ export const RouterLinkImpl = defineComponent({

// export the public type for h/tsx inference
// also to avoid inline import() in generated d.ts files
/**
* Component to render a link that triggers a navigation on click.
*/
export const RouterLink = (RouterLinkImpl as any) as {
new (): {
$props: AllowedComponentProps &
Expand Down
3 changes: 3 additions & 0 deletions src/RouterView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ export const RouterViewImpl = defineComponent({

// export the public type for h/tsx inference
// also to avoid inline import() in generated d.ts files
/**
* Component to display the current route the user is at.
*/
export const RouterView = (RouterViewImpl as any) as {
new (): {
$props: AllowedComponentProps &
Expand Down
8 changes: 2 additions & 6 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ const NavigationFailureSymbol = PolySymbol(
__DEV__ ? 'navigation failure' : 'nf'
)

interface RouterErrorBase extends Error {
type: ErrorTypes
}

export interface MatcherError extends RouterErrorBase {
export interface MatcherError extends Error {
type: ErrorTypes.MATCHER_NOT_FOUND
location: MatcherLocationRaw
currentLocation?: MatcherLocation
Expand Down Expand Up @@ -59,7 +55,7 @@ export enum NavigationFailureType {
/**
* Extended Error that contains extra information regarding a failed navigation.
*/
export interface NavigationFailure extends RouterErrorBase {
export interface NavigationFailure extends Error {
/**
* Type of the navigation. One of {@link NavigationFailureType}
*/
Expand Down
4 changes: 2 additions & 2 deletions src/history/html5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface StateEntry extends HistoryState {

/**
* Creates a normalized history location from a window.location object
* @param location
* @param location -
*/
function createCurrentLocation(
base: string,
Expand Down Expand Up @@ -274,7 +274,7 @@ function useHistoryStateNavigation(base: string) {
/**
* Creates an HTML5 history. Most common history for single page applications.
*
* @param base
* @param base -
*/
export function createWebHistory(base?: string): RouterHistory {
base = normalizeBase(base)
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,9 @@ export { RouterView, RouterViewProps } from './RouterView'
export * from './useApi'

export * from './globalExtensions'

/**
* The official Router for Vue 3.
*
* @packageDocumentation
*/
2 changes: 1 addition & 1 deletion src/matcher/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface RouteRecordNormalized {
*/
props: Record<string, _RouteRecordProps>
/**
* {@inheritDoc _RouteRecordBase.props}
* Registered beforeEnter guards
*/
beforeEnter: RouteRecordMultipleViews['beforeEnter']
/**
Expand Down
4 changes: 4 additions & 0 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export type LocationQueryRaw = Record<
/**
* Transforms a queryString into a {@link LocationQuery} object. Accept both, a
* version with the leading `?` and without Should work as URLSearchParams
* @internal
*
* @param search - search string to parse
* @returns a query object
Expand Down Expand Up @@ -73,6 +75,8 @@ export function parseQuery(search: string): LocationQuery {
* Stringifies a {@link LocationQueryRaw} object. Like `URLSearchParams`, it
* doesn't prepend a `?`
*
* @internal
*
* @param query - query object to stringify
* @returns string version of the query without the leading `?`
*/
Expand Down
6 changes: 6 additions & 0 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export interface RouterScrollBehavior {
): Awaitable<ScrollPosition | false | void>
}

/**
* Options to initialize a {@link Router} instance.
*/
export interface RouterOptions extends PathParserOptions {
/**
* History implementation used by the router. Most web applications should use
Expand Down Expand Up @@ -158,6 +161,9 @@ export interface RouterOptions extends PathParserOptions {
// linkInactiveClass?: string
}

/**
* Router instance
*/
export interface Router {
/**
* @internal
Expand Down
3 changes: 3 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ export interface _RouteRecordBase extends PathParserOptions {
meta?: RouteMeta
}

/**
* Interface to type `meta` fields in route records.
*/
export interface RouteMeta extends Record<string | number | symbol, any> {}

export type RouteRecordRedirectOption =
Expand Down
8 changes: 8 additions & 0 deletions src/useApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ import { routerKey, routeLocationKey } from './injectionSymbols'
import { Router } from './router'
import { RouteLocationNormalizedLoaded } from './types'

/**
* Returns the router instance. Equivalent to using `$router` inside
* templates.
*/
export function useRouter(): Router {
return inject(routerKey)!
}

/**
* Returns the current route location. Equivalent to using `$route` inside
* templates.
*/
export function useRoute(): RouteLocationNormalizedLoaded {
return inject(routeLocationKey)!
}
Loading

0 comments on commit 889f86c

Please sign in to comment.