]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
refactor: use ts-expect-error
authorEduardo San Martin Morote <posva13@gmail.com>
Tue, 1 Jun 2021 20:33:38 +0000 (22:33 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Tue, 1 Jun 2021 20:33:38 +0000 (22:33 +0200)
20 files changed:
__tests__/RouterLink.spec.ts
__tests__/guards/extractComponentsGuards.spec.ts
__tests__/matcher/addingRemoving.spec.ts
__tests__/matcher/pathRanking.spec.ts
__tests__/matcher/resolve.spec.ts
__tests__/mount.ts
__tests__/router.spec.ts
__tests__/urlEncoding.spec.ts
__tests__/utils.ts
e2e/guards-instances/index.ts
e2e/modal/index.ts
e2e/multi-app/index.ts
e2e/suspense/index.ts
playground/router.ts
src/RouterLink.ts
src/devtools.ts
src/history/memory.ts
src/navigationGuards.ts
src/router.ts
test-dts/meta.test-d.ts

index 34b65c428b757aa80fbbb0b75c39e0f9444def92..e3d76b685c2089af85b9105713392dc2a984c45f 100644 (file)
@@ -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<string>,
@@ -927,7 +927,7 @@ describe('RouterLink', () => {
 
         computed: {
           isExternalLink(): boolean {
-            // @ts-ignore
+            // @ts-expect-error
             return typeof this.to === 'string' && this.to.startsWith('http')
           },
         },
index 7dadb979b0b23af052a521c50f776dd22892a20e..8df52b48beb0004660ac54875215bc264746ae4a 100644 (file)
@@ -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')
index 276fa9aa7fa2196d9ab9fc403cf43c9caf37e852..7e72193777ee44908d2838eebeee0825b971140b 100644 (file)
@@ -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', () => {
index 86e9151a1979227ffa3e3fb3faa541c4b2132ccd..ce6e688489f0816e18a8fc7a27cd9cbc9205a259 100644 (file)
@@ -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: [],
         }
index 1a5b1edea342fe18e753a4d34f7957d37113fad7..916fe78e2708fe3f2b962111ca1b89fc6e6d0c11 100644 (file)
@@ -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 => ({
index 476012507e842cca76a30e2ccd2081ccef14d983..d5a4574488e875c45b1eebf147ff87f5cedacc39 100644 (file)
@@ -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])
index f55a2798c0de32ab677bd5a1b30f2d5c8090a734..957b9b89230fa4047f99ada61312930f5828f0f8 100644 (file)
@@ -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'
     )
index 5c34f0bc6869ad3de8a38823958e1d53284b9a53..82b7fd19272839f3d9a82340437d12663e0d6c84 100644 (file)
@@ -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')
index d017b559b650232c010319c36bd47729381ede55..8eddc12cca9bb4f022b307488afd0c2e0096bf68 100644 (file)
@@ -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
index f8bf36e84b678baee43f5ab36fb7eda25b5b7e0e..4dcb26698889b069f2ecd1f1b67e7c2beac879dd 100644 (file)
@@ -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')
index 0ed4a90cbecd4f46de0caa3e14f58be76bb6c154..a1659a639bf5ba269232902a6d9e6829c8a6536a 100644 (file)
@@ -203,5 +203,5 @@ const app = createApp({
 app.use(router)
 
 window.vm = app.mount('#app')
-// @ts-ignore
+// @ts-expect-error
 window.router = router
index 1c5d38838a305eced766f7c5b36355ae00a069b4..841adde4f3bb1e5321c96deafbdee9410089fd46 100644 (file)
@@ -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()
   },
index 9ec46a7760d6b576a3c357100d139553fa2ce71c..3d7ec62702dd00994a04e185de210eab5390ba3c 100644 (file)
@@ -104,7 +104,6 @@ leaves: {{ state.leave }}
 
 app.use(router)
 
-// @ts-ignore
 window.r = router
 
 app.mount('#app')
index cab05b8eb77a79211a6d6839dcbda300bc86063f..230b187cae97c9537fd6cf03892121e8951eb834 100644 (file)
@@ -257,7 +257,7 @@ export function go(delta: number) {
   })
 }
 
-// @ts-ignore
+// @ts-expect-error
 window._go = go
 
 router.beforeEach((to, from, next) => {
index d6720bae347f17118e7d4d18413bef4befca9d1a..aef8e176a200bb99b6a31d037e627189128ae835 100644 (file)
@@ -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
   }
index 97677dabc1e5490cf9cb4837a971e39c0136426f..1b270b1677e912e7ab6c42847a5dff7286cfaef9 100644 (file)
@@ -529,7 +529,7 @@ function omit<T extends object, K extends [...(keyof T)[]]>(obj: T, keys: K) {
 
   for (let key in obj) {
     if (!keys.includes(key as any)) {
-      // @ts-ignore
+      // @ts-expect-error
       ret[key] = obj[key]
     }
   }
index 5d3684f9fa5e755cacaefcdcd5459668c2d8f659..23648ee0e4df651797eea82f32162d4dfe3452eb 100644 (file)
@@ -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)
index 9b6de947648c894adeb8dac362265da878ac2859..8bb14f7b0bc0ca85cefaeeb40e76a39ea3ce1c4a 100644 (file)
@@ -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)
   }
index c4d6ef1fe24edc0e137a99b4a329a44ca558bc71..1825a3e0561a643d24ebbf9a6ee69495220cfd18 100644 (file)
@@ -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])
       }
 
index 29566a277389a284f2c114e17f5f246d6d6f352a..a27da5400d63a494976ba002fade03ef321f0d16 100644 (file)
@@ -26,7 +26,7 @@ const router = createRouter({
     },
     {
       path: '/foo',
-      // @ts-ignore
+      // @ts-expect-error
       component,
       // @ts-expect-error
       meta: {},