Skip to content

Commit

Permalink
feat: add vue 2.7 types
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxiangmoe authored and posva committed Aug 22, 2022
1 parent 9861c55 commit cba9650
Show file tree
Hide file tree
Showing 7 changed files with 431 additions and 25 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
dist
*.ts
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
},
"./composables": {
"import": "./dist/composables.mjs",
"require": "./dist/composables.js"
"require": "./dist/composables.js",
"types": "./types/composables.d.ts"
},
"./dist/*": "./dist/*",
"./types/*": "./types/*",
Expand Down
6 changes: 6 additions & 0 deletions src/composables/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,9 @@ function throwNoCurrentInstance (method) {
`[vue-router]: Missing current instance. ${method}() must be called inside <script setup> or setup().`
)
}

export { default as default } from '../index'
export { default as RouterLink } from '../components/link'
export { default as RouterView } from '../components/view'
export { NavigationFailureType, isNavigationFailure } from '../util/errors'
export { START as START_LOCATION } from '../util/route'
47 changes: 47 additions & 0 deletions types/composables.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Route, VueRouter, NavigationGuard } from './router'

/**
* Returns the current route location. Equivalent to using `$route` inside templates.
*/
export declare function useRoute(): Route
/**
* Returns the router instance. Equivalent to using `$router` inside templates.
*/
export declare function useRouter(): VueRouter
/**
* Add a navigation guard that triggers whenever the current location is about to be updated. Similar to beforeRouteUpdate but can be used in any component. The guard is removed when the component is unmounted.
*
* @param updateGuard NavigationGuard
*/
export declare function onBeforeRouteUpdate(updateGuard: NavigationGuard): void
/**
* Add a navigation guard that triggers whenever the component for the current location is about to be left. Similar to beforeRouteLeave but can be used in any component. The guard is removed when the component is unmounted.
*
* @param leaveGuard NavigationGuard
*/
export declare function onBeforeRouteLeave(leaveGuard: NavigationGuard): void

export {
type RouterMode,
type RouteMeta,
type RawLocation,
type RedirectOption,
type RouterOptions,
type RouteConfig,
type RouteRecord,
type RouteRecordPublic,
type Location,
type Route,
type NavigationGuard,
type NavigationGuardNext,
type NavigationFailure,
NavigationFailureType,
isNavigationFailure,
START_LOCATION,
type RouterViewProps,
RouterView,
type RouterLinkProps,
type RouterLinkSlotArgument,
RouterLink,
VueRouter as default,
} from './router'
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { VueRouter } from './router'

export default VueRouter

export {
export type {
RouterMode,
RouteMeta,
RawLocation,
Expand Down
Loading

0 comments on commit cba9650

Please sign in to comment.