Skip to content

Commit

Permalink
fix: split types from index to avoid types pollution
Browse files Browse the repository at this point in the history
Fix #136
  • Loading branch information
posva committed Mar 9, 2023
1 parent 2eef836 commit 4026948
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 52 deletions.
4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -56,6 +56,10 @@
"require": "./dist/runtime.js",
"import": "./dist/runtime.mjs"
},
"./types": {
"require": "./dist/types.js",
"import": "./dist/types.mjs"
},
"./*": "./*"
},
"files": [
Expand Down
4 changes: 2 additions & 2 deletions playground/typed-router.d.ts
Expand Up @@ -31,7 +31,7 @@ import type {
// data fetching
_DataLoader,
_DefineLoaderOptions,
} from 'unplugin-vue-router'
} from 'unplugin-vue-router/types'

declare module 'vue-router/auto/routes' {
export interface RouteNamedMap {
Expand Down Expand Up @@ -127,7 +127,7 @@ declare module 'vue-router/auto' {
export function onBeforeRouteUpdate(guard: NavigationGuard<RouteNamedMap>): void

export const RouterLink: RouterLinkTyped<RouteNamedMap>

// Experimental Data Fetching

export function defineLoader<
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/generateDTS.ts
Expand Up @@ -40,7 +40,7 @@ import type {
// data fetching
_DataLoader,
_DefineLoaderOptions,
} from 'unplugin-vue-router'
} from 'unplugin-vue-router/types'
declare module '${routesModule}' {
${routeNamedMap}
Expand Down Expand Up @@ -100,7 +100,7 @@ declare module '${vueRouterModule}' {
export function onBeforeRouteUpdate(guard: NavigationGuard<RouteNamedMap>): void
export const RouterLink: RouterLinkTyped<RouteNamedMap>
// Experimental Data Fetching
export function defineLoader<
Expand Down
54 changes: 6 additions & 48 deletions src/index.ts
Expand Up @@ -13,7 +13,9 @@ import { createViteContext } from './core/vite'
import { createFilter } from '@rollup/pluginutils'
import { join } from 'pathe'

export { Options, DEFAULT_OPTIONS }
export * from './types'

export { DEFAULT_OPTIONS }

export default createUnplugin<Options | undefined>((opt = {}, meta) => {
const options = resolveOptions(opt)
Expand Down Expand Up @@ -135,55 +137,11 @@ export default createUnplugin<Options | undefined>((opt = {}, meta) => {
export { createRoutesContext }
export { getFileBasedRouteName, getPascalCaseRouteName } from './core/utils'

export type {
_RouteMapGeneric,
RouteRecordInfo,
} from './codegen/generateRouteMap'
export type {
// TODO: mark all of these as internals since the dynamically exposed versions are fully typed, these are just helpers
// to generate the convenient types
RouteLocationAsRelativeTyped,
RouteLocationAsRelativeTypedList,
RouteLocationAsPathTyped,
RouteLocationAsPathTypedList,
RouteLocationAsString,
RouteLocationTyped,
RouteLocationTypedList,
RouteLocationResolvedTyped,
RouteLocationResolvedTypedList,
RouteLocationNormalizedTyped,
RouteLocationNormalizedTypedList,
RouteLocationNormalizedLoadedTyped,
RouteLocationNormalizedLoadedTypedList,
} from './typeExtensions/routeLocation'
export type { NavigationGuard } from './typeExtensions/navigationGuards'
export type { _RouterTyped } from './typeExtensions/router'
export type {
RouterLinkTyped,
UseLinkFnTyped,
_UseLinkReturnTyped,
} from './typeExtensions/RouterLink'
export type {
ParamValue,
ParamValueOneOrMore,
ParamValueZeroOrMore,
ParamValueZeroOrOne,
} from './codegen/generateRouteParams'

export { TreeNode, createPrefixTree } from './core/tree'
export {
createTreeNodeValue,
TreeNodeValueParam,
TreeNodeValueStatic,
} from './core/treeNodeValue'
// Route Tree and edition
export { createPrefixTree } from './core/tree'
export { createTreeNodeValue } from './core/treeNodeValue'
export { EditableTreeNode } from './core/extendRoutes'

// expose for generated type extensions
export type {
DefineLoaderOptions as _DefineLoaderOptions,
DataLoader as _DataLoader,
} from './data-fetching/defineLoader'

/**
* @deprecated use `VueRouterAutoImports` instead
*/
Expand Down
53 changes: 53 additions & 0 deletions src/types.ts
@@ -0,0 +1,53 @@
/**
* This file only contain types and is used for the generated d.ts to avoid polluting the global namespace.
* https://github.com/posva/unplugin-vue-router/issues/136
*/

export type { Options } from './options'

export type {
_RouteMapGeneric,
RouteRecordInfo,
} from './codegen/generateRouteMap'
export type {
// TODO: mark all of these as internals since the dynamically exposed versions are fully typed, these are just helpers
// to generate the convenient types
RouteLocationAsRelativeTyped,
RouteLocationAsRelativeTypedList,
RouteLocationAsPathTyped,
RouteLocationAsPathTypedList,
RouteLocationAsString,
RouteLocationTyped,
RouteLocationTypedList,
RouteLocationResolvedTyped,
RouteLocationResolvedTypedList,
RouteLocationNormalizedTyped,
RouteLocationNormalizedTypedList,
RouteLocationNormalizedLoadedTyped,
RouteLocationNormalizedLoadedTypedList,
} from './typeExtensions/routeLocation'
export type { NavigationGuard } from './typeExtensions/navigationGuards'
export type { _RouterTyped } from './typeExtensions/router'
export type {
RouterLinkTyped,
UseLinkFnTyped,
_UseLinkReturnTyped,
} from './typeExtensions/RouterLink'
export type {
ParamValue,
ParamValueOneOrMore,
ParamValueZeroOrMore,
ParamValueZeroOrOne,
} from './codegen/generateRouteParams'

export type { TreeNode } from './core/tree'
export type {
TreeNodeValueParam,
TreeNodeValueStatic,
} from './core/treeNodeValue'

// expose for generated type extensions
export type {
DefineLoaderOptions as _DefineLoaderOptions,
DataLoader as _DataLoader,
} from './data-fetching/defineLoader'

0 comments on commit 4026948

Please sign in to comment.