From: Eduardo San Martin Morote Date: Fri, 31 Jan 2020 18:04:59 +0000 (+0100) Subject: refactor: types X-Git-Tag: v4.0.0-alpha.0~65 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=564615a906c24bc4170ad1998ca62079faf51a97;p=thirdparty%2Fvuejs%2Frouter.git refactor: types --- diff --git a/__tests__/RouterView.spec.ts b/__tests__/RouterView.spec.ts index 001af68f..b88b57c0 100644 --- a/__tests__/RouterView.spec.ts +++ b/__tests__/RouterView.spec.ts @@ -1,16 +1,13 @@ /** * @jest-environment jsdom */ -import RouterView from '../src/components/View' -import { components } from './utils' -import { - START_LOCATION_NORMALIZED, - RouteLocationNormalized, -} from '../src/types' +import { View as RouterView } from '../src/components/View' +import { components, RouteLocationNormalizedLoose } from './utils' +import { START_LOCATION_NORMALIZED } from '../src/types' import { ref, markNonReactive } from 'vue' import { mount, tick } from './mount' -const routes: Record = { +const routes: Record = { root: { fullPath: '/', name: undefined, @@ -71,7 +68,7 @@ const routes: Record = { } describe('RouterView', () => { - function factory(route: RouteLocationNormalized, props: any = {}) { + function factory(route: RouteLocationNormalizedLoose, props: any = {}) { const router = { currentRoute: ref(markNonReactive(route)), } @@ -105,7 +102,7 @@ describe('RouterView', () => { }) it('displays nothing when route is unmatched', () => { - const { el } = factory(START_LOCATION_NORMALIZED) + const { el } = factory(START_LOCATION_NORMALIZED as any) // NOTE: I wonder if this will stay stable in future releases expect(el.childElementCount).toBe(0) }) diff --git a/__tests__/matcher/resolve.spec.ts b/__tests__/matcher/resolve.spec.ts index c6788fc6..1a380614 100644 --- a/__tests__/matcher/resolve.spec.ts +++ b/__tests__/matcher/resolve.spec.ts @@ -6,9 +6,8 @@ import { MatcherLocation, MatcherLocationNormalized, MatcherLocationRedirect, - RouteRecordMultipleViews, } from '../../src/types' -import { normalizeRouteRecord } from '../utils' +import { normalizeRouteRecord, MatcherLocationNormalizedLoose } from '../utils' // @ts-ignore const component: RouteComponent = null @@ -16,21 +15,6 @@ const component: RouteComponent = null // for normalized records const components = { default: component } -interface MatcherLocationNormalizedLoose { - name: string - path: string - // record? - params: any - redirectedFrom?: Partial - meta: any - matched: Partial[] -} - -type RouteRecordViewLoose = Pick< - RouteRecordMultipleViews, - 'path' | 'name' | 'components' | 'children' | 'meta' | 'beforeEnter' -> - describe('Router Matcher', () => { describe('resolve', () => { function assertRecordMatch( diff --git a/__tests__/utils.ts b/__tests__/utils.ts index d786d4fa..9e5c45a7 100644 --- a/__tests__/utils.ts +++ b/__tests__/utils.ts @@ -1,6 +1,12 @@ import { JSDOM, ConstructorOptions } from 'jsdom' -import { NavigationGuard, RouteRecord } from '../src/types' -import { h, resolveComponent } from '@vue/runtime-core' +import { + NavigationGuard, + RouteRecord, + RouteRecordMultipleViews, + MatcherLocationNormalized, + RouteLocationNormalized, +} from '../src/types' +import { h, resolveComponent } from 'vue' import { RouteRecordMatched } from '../src/matcher/types' export const tick = (time?: number) => @@ -12,6 +18,35 @@ export const tick = (time?: number) => export type NAVIGATION_METHOD = 'push' | 'replace' export const NAVIGATION_TYPES: NAVIGATION_METHOD[] = ['push', 'replace'] +export interface RouteRecordViewLoose + extends Pick< + RouteRecordMultipleViews, + 'path' | 'name' | 'components' | 'children' | 'meta' | 'beforeEnter' + > { + leaveGuards?: any +} + +// @ts-ignore we are intentionally overriding the type +export interface RouteLocationNormalizedLoose extends RouteLocationNormalized { + name: string | undefined + path: string + // record? + params: any + redirectedFrom?: Partial + meta: any + matched: Partial[] +} + +export interface MatcherLocationNormalizedLoose { + name: string + path: string + // record? + params: any + redirectedFrom?: Partial + meta: any + matched: Partial[] +} + declare global { namespace NodeJS { interface Global { diff --git a/playground/views/GuardedWithLeave.vue b/playground/views/GuardedWithLeave.vue index 0e4e73eb..c56547b9 100644 --- a/playground/views/GuardedWithLeave.vue +++ b/playground/views/GuardedWithLeave.vue @@ -8,7 +8,7 @@