From c482e19f1983ce4d96072aa42ecb3c6923dcd324 Mon Sep 17 00:00:00 2001 From: qwqcode Date: Sun, 7 Apr 2024 20:10:19 +0800 Subject: [PATCH] chore(sidebar): fix build type issue when upgrade deps https://github.com/posva/unplugin-vue-router/issues/353 --- ui/artalk-sidebar/auto-imports.d.ts | 2 +- ui/artalk-sidebar/env.d.ts | 1 + ui/artalk-sidebar/typed-router.d.ts | 140 +++------------------------- 3 files changed, 13 insertions(+), 130 deletions(-) diff --git a/ui/artalk-sidebar/auto-imports.d.ts b/ui/artalk-sidebar/auto-imports.d.ts index 056610d63..24c848623 100644 --- a/ui/artalk-sidebar/auto-imports.d.ts +++ b/ui/artalk-sidebar/auto-imports.d.ts @@ -12,7 +12,7 @@ declare global { const defineAsyncComponent: typeof import('vue')['defineAsyncComponent'] const defineComponent: typeof import('vue')['defineComponent'] const defineLoader: typeof import('vue-router/auto')['defineLoader'] - const definePage: typeof import('unplugin-vue-router/runtime')['_definePage'] + const definePage: typeof import('unplugin-vue-router/runtime')['definePage'] const effectScope: typeof import('vue')['effectScope'] const getCurrentInstance: typeof import('vue')['getCurrentInstance'] const getCurrentScope: typeof import('vue')['getCurrentScope'] diff --git a/ui/artalk-sidebar/env.d.ts b/ui/artalk-sidebar/env.d.ts index 11f02fe2a..dabd0deba 100644 --- a/ui/artalk-sidebar/env.d.ts +++ b/ui/artalk-sidebar/env.d.ts @@ -1 +1,2 @@ /// +/// diff --git a/ui/artalk-sidebar/typed-router.d.ts b/ui/artalk-sidebar/typed-router.d.ts index 6c3487687..662bfaa68 100644 --- a/ui/artalk-sidebar/typed-router.d.ts +++ b/ui/artalk-sidebar/typed-router.d.ts @@ -5,39 +5,18 @@ // It's recommended to commit this file. // Make sure to add this file to your tsconfig.json file as an "includes" or "files" entry. -/// +declare module 'vue-router/auto-routes' { + import type { + RouteRecordInfo, + ParamValue, + ParamValueOneOrMore, + ParamValueZeroOrMore, + ParamValueZeroOrOne, + } from 'unplugin-vue-router/types' -import type { - // type safe route locations - RouteLocationTypedList, - RouteLocationResolvedTypedList, - RouteLocationNormalizedTypedList, - RouteLocationNormalizedLoadedTypedList, - RouteLocationAsString, - RouteLocationAsRelativeTypedList, - RouteLocationAsPathTypedList, - - // helper types - // route definitions - RouteRecordInfo, - ParamValue, - ParamValueOneOrMore, - ParamValueZeroOrMore, - ParamValueZeroOrOne, - - // vue-router extensions - _RouterTyped, - RouterLinkTyped, - RouterLinkPropsTyped, - NavigationGuard, - UseLinkFnTyped, - - // data fetching - _DataLoader, - _DefineLoaderOptions, -} from 'unplugin-vue-router/types' - -declare module 'vue-router/auto/routes' { + /** + * Route name map generated by unplugin-vue-router + */ export interface RouteNamedMap { '/': RouteRecordInfo<'/', '/', Record, Record>, '/comments': RouteRecordInfo<'/comments', '/comments', Record, Record>, @@ -49,100 +28,3 @@ declare module 'vue-router/auto/routes' { '/users': RouteRecordInfo<'/users', '/users', Record, Record>, } } - -declare module 'vue-router/auto' { - import type { RouteNamedMap } from 'vue-router/auto/routes' - - export type RouterTyped = _RouterTyped - - /** - * Type safe version of `RouteLocationNormalized` (the type of `to` and `from` in navigation guards). - * Allows passing the name of the route to be passed as a generic. - */ - export type RouteLocationNormalized = RouteLocationNormalizedTypedList[Name] - - /** - * Type safe version of `RouteLocationNormalizedLoaded` (the return type of `useRoute()`). - * Allows passing the name of the route to be passed as a generic. - */ - export type RouteLocationNormalizedLoaded = RouteLocationNormalizedLoadedTypedList[Name] - - /** - * Type safe version of `RouteLocationResolved` (the returned route of `router.resolve()`). - * Allows passing the name of the route to be passed as a generic. - */ - export type RouteLocationResolved = RouteLocationResolvedTypedList[Name] - - /** - * Type safe version of `RouteLocation` . Allows passing the name of the route to be passed as a generic. - */ - export type RouteLocation = RouteLocationTypedList[Name] - - /** - * Type safe version of `RouteLocationRaw` . Allows passing the name of the route to be passed as a generic. - */ - export type RouteLocationRaw = - | RouteLocationAsString - | RouteLocationAsRelativeTypedList[Name] - | RouteLocationAsPathTypedList[Name] - - /** - * Generate a type safe params for a route location. Requires the name of the route to be passed as a generic. - */ - export type RouteParams = RouteNamedMap[Name]['params'] - /** - * Generate a type safe raw params for a route location. Requires the name of the route to be passed as a generic. - */ - export type RouteParamsRaw = RouteNamedMap[Name]['paramsRaw'] - - export function useRouter(): RouterTyped - export function useRoute(name?: Name): RouteLocationNormalizedLoadedTypedList[Name] - - export const useLink: UseLinkFnTyped - - export function onBeforeRouteLeave(guard: NavigationGuard): void - export function onBeforeRouteUpdate(guard: NavigationGuard): void - - export const RouterLink: RouterLinkTyped - export const RouterLinkProps: RouterLinkPropsTyped - - // Experimental Data Fetching - - export function defineLoader< - P extends Promise, - Name extends keyof RouteNamedMap = keyof RouteNamedMap, - isLazy extends boolean = false, - >( - name: Name, - loader: (route: RouteLocationNormalizedLoaded) => P, - options?: _DefineLoaderOptions, - ): _DataLoader, isLazy> - export function defineLoader< - P extends Promise, - isLazy extends boolean = false, - >( - loader: (route: RouteLocationNormalizedLoaded) => P, - options?: _DefineLoaderOptions, - ): _DataLoader, isLazy> - - export { - _definePage as definePage, - _HasDataLoaderMeta as HasDataLoaderMeta, - _setupDataFetchingGuard as setupDataFetchingGuard, - _stopDataFetchingScope as stopDataFetchingScope, - } from 'unplugin-vue-router/runtime' -} - -declare module 'vue-router' { - import type { RouteNamedMap } from 'vue-router/auto/routes' - - export interface TypesConfig { - beforeRouteUpdate: NavigationGuard - beforeRouteLeave: NavigationGuard - - $route: RouteLocationNormalizedLoadedTypedList[keyof RouteNamedMap] - $router: _RouterTyped - - RouterLink: RouterLinkTyped - } -}