From 20f4580d4b1ba7e30e6b2d522e0da0a1687622a7 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 1 Jun 2021 22:33:38 +0200 Subject: [PATCH] refactor: use ts-expect-error --- __tests__/RouterLink.spec.ts | 4 ++-- .../guards/extractComponentsGuards.spec.ts | 5 ++-- __tests__/matcher/addingRemoving.spec.ts | 2 +- __tests__/matcher/pathRanking.spec.ts | 6 ++--- __tests__/matcher/resolve.spec.ts | 6 ++--- __tests__/mount.ts | 2 +- __tests__/router.spec.ts | 2 +- __tests__/urlEncoding.spec.ts | 24 +++++++++---------- __tests__/utils.ts | 4 ++-- e2e/guards-instances/index.ts | 3 +-- e2e/modal/index.ts | 2 +- e2e/multi-app/index.ts | 5 ++-- e2e/suspense/index.ts | 1 - playground/router.ts | 2 +- src/RouterLink.ts | 4 ++-- src/devtools.ts | 2 +- src/history/memory.ts | 2 +- src/navigationGuards.ts | 6 ++--- src/router.ts | 6 ++--- test-dts/meta.test-d.ts | 2 +- 20 files changed, 41 insertions(+), 49 deletions(-) diff --git a/__tests__/RouterLink.spec.ts b/__tests__/RouterLink.spec.ts index 34b65c428..e3d76b685 100644 --- a/__tests__/RouterLink.spec.ts +++ b/__tests__/RouterLink.spec.ts @@ -919,7 +919,7 @@ describe('RouterLink', () => { components: { RouterLink }, name: 'AppLink', - // @ts-ignore + // @ts-expect-error props: { ...((RouterLink as any).props as RouterLinkProps), inactiveClass: String as PropType, @@ -927,7 +927,7 @@ describe('RouterLink', () => { computed: { isExternalLink(): boolean { - // @ts-ignore + // @ts-expect-error return typeof this.to === 'string' && this.to.startsWith('http') }, }, diff --git a/__tests__/guards/extractComponentsGuards.spec.ts b/__tests__/guards/extractComponentsGuards.spec.ts index 7dadb979b..8df52b48b 100644 --- a/__tests__/guards/extractComponentsGuards.spec.ts +++ b/__tests__/guards/extractComponentsGuards.spec.ts @@ -14,12 +14,11 @@ const from = START_LOCATION_NORMALIZED const NoGuard: RouteRecordRaw = { path: '/', component: components.Home } const InvalidRoute: RouteRecordRaw = { path: '/', - // @ts-ignore: intended error + // @ts-expect-error component: null, } const WrongLazyRoute: RouteRecordRaw = { path: '/', - // @ts-ignore: intended error component: Promise.resolve(components.Home), } const SingleGuard: RouteRecordRaw = { @@ -88,7 +87,7 @@ describe('extractComponentsGuards', () => { }) it('throws if component is null', async () => { - // @ts-ignore + // @ts-expect-error await expect(checkGuards([InvalidRoute], 2)).rejects.toHaveProperty( 'message', expect.stringMatching('Invalid route component') diff --git a/__tests__/matcher/addingRemoving.spec.ts b/__tests__/matcher/addingRemoving.spec.ts index 276fa9aa7..7e7219377 100644 --- a/__tests__/matcher/addingRemoving.spec.ts +++ b/__tests__/matcher/addingRemoving.spec.ts @@ -3,7 +3,7 @@ import { MatcherLocation } from '../../src/types' import { mockWarn } from 'jest-mock-warn' const currentLocation = { path: '/' } as MatcherLocation -// @ts-ignore +// @ts-expect-error const component: RouteComponent = null describe('Matcher: adding and removing records', () => { diff --git a/__tests__/matcher/pathRanking.spec.ts b/__tests__/matcher/pathRanking.spec.ts index 86e9151a1..ce6e68848 100644 --- a/__tests__/matcher/pathRanking.spec.ts +++ b/__tests__/matcher/pathRanking.spec.ts @@ -13,18 +13,16 @@ describe('Path ranking', () => { { score: a, re: /a/, - // @ts-ignore + // @ts-expect-error stringify: v => v, - // @ts-ignore + // @ts-expect-error parse: v => v, keys: [], }, { score: b, re: /a/, - // @ts-ignore stringify: v => v, - // @ts-ignore parse: v => v, keys: [], } diff --git a/__tests__/matcher/resolve.spec.ts b/__tests__/matcher/resolve.spec.ts index 1a5b1edea..916fe78e2 100644 --- a/__tests__/matcher/resolve.spec.ts +++ b/__tests__/matcher/resolve.spec.ts @@ -9,7 +9,7 @@ import { import { MatcherLocationNormalizedLoose } from '../utils' import { mockWarn } from 'jest-mock-warn' -// @ts-ignore +// @ts-expect-error const component: RouteComponent = null // for normalized records @@ -42,9 +42,7 @@ describe('RouterMatcher.resolve', () => { throw new Error('not handled') } else { // use one single record - if (!resolved.matched) - // @ts-ignore - resolved.matched = record.map(normalizeRouteRecord) + if (!resolved.matched) resolved.matched = record.map(normalizeRouteRecord) // allow passing an expect.any(Array) else if (Array.isArray(resolved.matched)) resolved.matched = resolved.matched.map(m => ({ diff --git a/__tests__/mount.ts b/__tests__/mount.ts index 476012507..d5a457448 100644 --- a/__tests__/mount.ts +++ b/__tests__/mount.ts @@ -20,7 +20,7 @@ export function createMockedRoute(initialValue: RouteLocationNormalizedLoose) { } for (let key in initialValue) { - // @ts-ignore + // @ts-expect-error route[key] = // new line to still get errors here computed(() => routeRef.value[key as keyof RouteLocationNormalizedLoose]) diff --git a/__tests__/router.spec.ts b/__tests__/router.spec.ts index f55a2798c..957b9b892 100644 --- a/__tests__/router.spec.ts +++ b/__tests__/router.spec.ts @@ -95,7 +95,7 @@ describe('Router', () => { }) it('fails if history option is missing', () => { - // @ts-ignore + // @ts-expect-error expect(() => createRouter({ routes })).toThrowError( 'Provide the "history" option' ) diff --git a/__tests__/urlEncoding.spec.ts b/__tests__/urlEncoding.spec.ts index 5c34f0bc6..82b7fd192 100644 --- a/__tests__/urlEncoding.spec.ts +++ b/__tests__/urlEncoding.spec.ts @@ -25,11 +25,11 @@ describe('URL Encoding', () => { beforeEach(() => { // mock all encoding functions for (const key in encoding) { - // @ts-ignore + // @ts-expect-error const value = encoding[key] - // @ts-ignore + // @ts-expect-error if (typeof value === 'function') encoding[key] = jest.fn((v: string) => v) - // @ts-ignore + // @ts-expect-error else if (key === 'PLUS_RE') encoding[key] = /\+/g } }) @@ -82,9 +82,9 @@ describe('URL Encoding', () => { }) it('decodes values in params', async () => { - // @ts-ignore: override to make the difference + // @ts-expect-error: override to make the difference encoding.decode = () => 'd' - // @ts-ignore + // @ts-expect-error encoding.encodeParam = () => 'e' const router = createRouter() await router.push({ name: 'optional', params: { a: 'a%' } }) @@ -124,11 +124,11 @@ describe('URL Encoding', () => { }) it('keeps decoded values in query', async () => { - // @ts-ignore: override to make the difference + // @ts-expect-error: override to make the difference encoding.decode = () => 'd' - // @ts-ignore + // @ts-expect-error encoding.encodeQueryValue = () => 'ev' - // @ts-ignore + // @ts-expect-error encoding.encodeQueryKey = () => 'ek' const router = createRouter() await router.push({ name: 'home', query: { p: '%' } }) @@ -139,9 +139,9 @@ describe('URL Encoding', () => { }) it('keeps decoded values in hash', async () => { - // @ts-ignore: override to make the difference + // @ts-expect-error: override to make the difference encoding.decode = () => 'd' - // @ts-ignore + // @ts-expect-error encoding.encodeHash = () => '#e' const router = createRouter() await router.push({ name: 'home', hash: '#%' }) @@ -151,9 +151,9 @@ describe('URL Encoding', () => { }) }) it('decodes hash', async () => { - // @ts-ignore: override to make the difference + // @ts-expect-error: override to make the difference encoding.decode = () => '#d' - // @ts-ignore + // @ts-expect-error encoding.encodeHash = () => '#e' const router = createRouter() await router.push('#%20') diff --git a/__tests__/utils.ts b/__tests__/utils.ts index d017b559b..8eddc12cc 100644 --- a/__tests__/utils.ts +++ b/__tests__/utils.ts @@ -60,7 +60,7 @@ export interface RouteRecordViewLoose aliasOf: RouteRecordViewLoose | undefined } -// @ts-ignore we are intentionally overriding the type +// @ts-expect-error we are intentionally overriding the type export interface RouteLocationNormalizedLoose extends RouteLocationNormalized { name: RouteRecordName | null | undefined path: string @@ -105,7 +105,7 @@ export function createDom(options?: ConstructorOptions) { } ) - // @ts-ignore: needed for jsdom + // @ts-expect-error: needed for jsdom global.window = dom.window global.location = dom.window.location global.history = dom.window.history diff --git a/e2e/guards-instances/index.ts b/e2e/guards-instances/index.ts index f8bf36e84..4dcb26698 100644 --- a/e2e/guards-instances/index.ts +++ b/e2e/guards-instances/index.ts @@ -64,7 +64,7 @@ function createTestComponent(key: string) { state.enter++ logs.value.push(`${key}: enter ${from.path} - ${to.path}`) next(vm => { - // @ts-ignore + // @ts-expect-error vm.enterCallback++ }) }, @@ -239,7 +239,6 @@ leaves: {{ state.leave }} app.use(router) -// @ts-ignore window.r = router app.mount('#app') diff --git a/e2e/modal/index.ts b/e2e/modal/index.ts index 0ed4a90cb..a1659a639 100644 --- a/e2e/modal/index.ts +++ b/e2e/modal/index.ts @@ -203,5 +203,5 @@ const app = createApp({ app.use(router) window.vm = app.mount('#app') -// @ts-ignore +// @ts-expect-error window.router = router diff --git a/e2e/multi-app/index.ts b/e2e/multi-app/index.ts index 1c5d38838..841adde4f 100644 --- a/e2e/multi-app/index.ts +++ b/e2e/multi-app/index.ts @@ -12,9 +12,8 @@ const User: RouteComponent = { beforeRouteEnter(to, from, next) { next(vm => { - // @ts-ignore + // @ts-expect-error console.log('enter from ', vm.id) - // @ts-ignore }) }, @@ -41,7 +40,7 @@ const NamedViews: RouteComponent[] = looper.map(i => ({ beforeRouteUpdate(to, from, next) { console.log('update of', i) - // @ts-ignore + // @ts-expect-error this.count++ next() }, diff --git a/e2e/suspense/index.ts b/e2e/suspense/index.ts index 9ec46a776..3d7ec6270 100644 --- a/e2e/suspense/index.ts +++ b/e2e/suspense/index.ts @@ -104,7 +104,6 @@ leaves: {{ state.leave }} app.use(router) -// @ts-ignore window.r = router app.mount('#app') diff --git a/playground/router.ts b/playground/router.ts index cab05b8eb..230b187ca 100644 --- a/playground/router.ts +++ b/playground/router.ts @@ -257,7 +257,7 @@ export function go(delta: number) { }) } -// @ts-ignore +// @ts-expect-error window._go = go router.beforeEach((to, from, next) => { diff --git a/src/RouterLink.ts b/src/RouterLink.ts index d6720bae3..aef8e176a 100644 --- a/src/RouterLink.ts +++ b/src/RouterLink.ts @@ -231,9 +231,9 @@ function guardEvent(e: MouseEvent) { // don't redirect on right click if (e.button !== undefined && e.button !== 0) return // don't redirect if `target="_blank"` - // @ts-ignore getAttribute does exist + // @ts-expect-error getAttribute does exist if (e.currentTarget && e.currentTarget.getAttribute) { - // @ts-ignore getAttribute exists + // @ts-expect-error getAttribute exists const target = e.currentTarget.getAttribute('target') if (/\b_blank\b/i.test(target)) return } diff --git a/src/devtools.ts b/src/devtools.ts index 97677dabc..1b270b167 100644 --- a/src/devtools.ts +++ b/src/devtools.ts @@ -529,7 +529,7 @@ function omit(obj: T, keys: K) { for (let key in obj) { if (!keys.includes(key as any)) { - // @ts-ignore + // @ts-expect-error ret[key] = obj[key] } } diff --git a/src/history/memory.ts b/src/history/memory.ts index 5d3684f9f..23648ee0e 100644 --- a/src/history/memory.ts +++ b/src/history/memory.ts @@ -103,7 +103,7 @@ export function createMemoryHistory(base: string = ''): RouterHistory { }) if (__TEST__) { - // @ts-ignore: only for tests + // @ts-expect-error: only for tests routerHistory.changeURL = function (url: string) { const from = this.location queue.splice(position++ + 1, queue.length, url) diff --git a/src/navigationGuards.ts b/src/navigationGuards.ts index 9b6de9476..8bb14f7b0 100644 --- a/src/navigationGuards.ts +++ b/src/navigationGuards.ts @@ -185,7 +185,7 @@ export function guardToPromiseFn( }:\n${guard.toString()}\n. If you are returning a value instead of calling "next", make sure to remove the "next" parameter from your function.` if (typeof guardReturn === 'object' && 'then' in guardReturn) { guardCall = guardCall.then(resolvedValue => { - // @ts-ignore: _called is added at canOnlyBeCalledOnce + // @ts-expect-error: _called is added at canOnlyBeCalledOnce if (!next._called) { warn(message) return Promise.reject(new Error('Invalid navigation guard')) @@ -194,7 +194,7 @@ export function guardToPromiseFn( }) // TODO: test me! } else if (guardReturn !== undefined) { - // @ts-ignore: _called is added at canOnlyBeCalledOnce + // @ts-expect-error: _called is added at canOnlyBeCalledOnce if (!next._called) { warn(message) reject(new Error('Invalid navigation guard')) @@ -217,7 +217,7 @@ function canOnlyBeCalledOnce( warn( `The "next" callback was called more than once in one navigation guard when going from "${from.fullPath}" to "${to.fullPath}". It should be called exactly one time in each navigation guard. This will fail in production.` ) - // @ts-ignore: we put it in the original one because it's easier to check + // @ts-expect-error: we put it in the original one because it's easier to check next._called = true if (called === 1) next.apply(null, arguments as any) } diff --git a/src/router.ts b/src/router.ts index c4d6ef1fe..1825a3e05 100644 --- a/src/router.ts +++ b/src/router.ts @@ -681,9 +681,9 @@ export function createRouter(options: RouterOptions): Router { ) && // and we have done it a couple of times redirectedFrom && - // @ts-ignore + // @ts-expect-error (redirectedFrom._count = redirectedFrom._count - ? // @ts-ignore + ? // @ts-expect-error redirectedFrom._count + 1 : 1) > 10 ) { @@ -1129,7 +1129,7 @@ export function createRouter(options: RouterOptions): Router { > } for (let key in START_LOCATION_NORMALIZED) { - // @ts-ignore: the key matches + // @ts-expect-error: the key matches reactiveRoute[key] = computed(() => currentRoute.value[key]) } diff --git a/test-dts/meta.test-d.ts b/test-dts/meta.test-d.ts index 29566a277..a27da5400 100644 --- a/test-dts/meta.test-d.ts +++ b/test-dts/meta.test-d.ts @@ -26,7 +26,7 @@ const router = createRouter({ }, { path: '/foo', - // @ts-ignore + // @ts-expect-error component, // @ts-expect-error meta: {},