Skip to content

Commit 20f4580

Browse files
committed
refactor: use ts-expect-error
1 parent 3d465cc commit 20f4580

20 files changed

+41
-49
lines changed

__tests__/RouterLink.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -919,15 +919,15 @@ describe('RouterLink', () => {
919919
components: { RouterLink },
920920
name: 'AppLink',
921921

922-
// @ts-ignore
922+
// @ts-expect-error
923923
props: {
924924
...((RouterLink as any).props as RouterLinkProps),
925925
inactiveClass: String as PropType<string>,
926926
},
927927

928928
computed: {
929929
isExternalLink(): boolean {
930-
// @ts-ignore
930+
// @ts-expect-error
931931
return typeof this.to === 'string' && this.to.startsWith('http')
932932
},
933933
},

__tests__/guards/extractComponentsGuards.spec.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ const from = START_LOCATION_NORMALIZED
1414
const NoGuard: RouteRecordRaw = { path: '/', component: components.Home }
1515
const InvalidRoute: RouteRecordRaw = {
1616
path: '/',
17-
// @ts-ignore: intended error
17+
// @ts-expect-error
1818
component: null,
1919
}
2020
const WrongLazyRoute: RouteRecordRaw = {
2121
path: '/',
22-
// @ts-ignore: intended error
2322
component: Promise.resolve(components.Home),
2423
}
2524
const SingleGuard: RouteRecordRaw = {
@@ -88,7 +87,7 @@ describe('extractComponentsGuards', () => {
8887
})
8988

9089
it('throws if component is null', async () => {
91-
// @ts-ignore
90+
// @ts-expect-error
9291
await expect(checkGuards([InvalidRoute], 2)).rejects.toHaveProperty(
9392
'message',
9493
expect.stringMatching('Invalid route component')

__tests__/matcher/addingRemoving.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { MatcherLocation } from '../../src/types'
33
import { mockWarn } from 'jest-mock-warn'
44

55
const currentLocation = { path: '/' } as MatcherLocation
6-
// @ts-ignore
6+
// @ts-expect-error
77
const component: RouteComponent = null
88

99
describe('Matcher: adding and removing records', () => {

__tests__/matcher/pathRanking.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ describe('Path ranking', () => {
1313
{
1414
score: a,
1515
re: /a/,
16-
// @ts-ignore
16+
// @ts-expect-error
1717
stringify: v => v,
18-
// @ts-ignore
18+
// @ts-expect-error
1919
parse: v => v,
2020
keys: [],
2121
},
2222
{
2323
score: b,
2424
re: /a/,
25-
// @ts-ignore
2625
stringify: v => v,
27-
// @ts-ignore
2826
parse: v => v,
2927
keys: [],
3028
}

__tests__/matcher/resolve.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import { MatcherLocationNormalizedLoose } from '../utils'
1010
import { mockWarn } from 'jest-mock-warn'
1111

12-
// @ts-ignore
12+
// @ts-expect-error
1313
const component: RouteComponent = null
1414

1515
// for normalized records
@@ -42,9 +42,7 @@ describe('RouterMatcher.resolve', () => {
4242
throw new Error('not handled')
4343
} else {
4444
// use one single record
45-
if (!resolved.matched)
46-
// @ts-ignore
47-
resolved.matched = record.map(normalizeRouteRecord)
45+
if (!resolved.matched) resolved.matched = record.map(normalizeRouteRecord)
4846
// allow passing an expect.any(Array)
4947
else if (Array.isArray(resolved.matched))
5048
resolved.matched = resolved.matched.map(m => ({

__tests__/mount.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function createMockedRoute(initialValue: RouteLocationNormalizedLoose) {
2020
}
2121

2222
for (let key in initialValue) {
23-
// @ts-ignore
23+
// @ts-expect-error
2424
route[key] =
2525
// new line to still get errors here
2626
computed(() => routeRef.value[key as keyof RouteLocationNormalizedLoose])

__tests__/router.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('Router', () => {
9595
})
9696

9797
it('fails if history option is missing', () => {
98-
// @ts-ignore
98+
// @ts-expect-error
9999
expect(() => createRouter({ routes })).toThrowError(
100100
'Provide the "history" option'
101101
)

__tests__/urlEncoding.spec.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ describe('URL Encoding', () => {
2525
beforeEach(() => {
2626
// mock all encoding functions
2727
for (const key in encoding) {
28-
// @ts-ignore
28+
// @ts-expect-error
2929
const value = encoding[key]
30-
// @ts-ignore
30+
// @ts-expect-error
3131
if (typeof value === 'function') encoding[key] = jest.fn((v: string) => v)
32-
// @ts-ignore
32+
// @ts-expect-error
3333
else if (key === 'PLUS_RE') encoding[key] = /\+/g
3434
}
3535
})
@@ -82,9 +82,9 @@ describe('URL Encoding', () => {
8282
})
8383

8484
it('decodes values in params', async () => {
85-
// @ts-ignore: override to make the difference
85+
// @ts-expect-error: override to make the difference
8686
encoding.decode = () => 'd'
87-
// @ts-ignore
87+
// @ts-expect-error
8888
encoding.encodeParam = () => 'e'
8989
const router = createRouter()
9090
await router.push({ name: 'optional', params: { a: 'a%' } })
@@ -124,11 +124,11 @@ describe('URL Encoding', () => {
124124
})
125125

126126
it('keeps decoded values in query', async () => {
127-
// @ts-ignore: override to make the difference
127+
// @ts-expect-error: override to make the difference
128128
encoding.decode = () => 'd'
129-
// @ts-ignore
129+
// @ts-expect-error
130130
encoding.encodeQueryValue = () => 'ev'
131-
// @ts-ignore
131+
// @ts-expect-error
132132
encoding.encodeQueryKey = () => 'ek'
133133
const router = createRouter()
134134
await router.push({ name: 'home', query: { p: '%' } })
@@ -139,9 +139,9 @@ describe('URL Encoding', () => {
139139
})
140140

141141
it('keeps decoded values in hash', async () => {
142-
// @ts-ignore: override to make the difference
142+
// @ts-expect-error: override to make the difference
143143
encoding.decode = () => 'd'
144-
// @ts-ignore
144+
// @ts-expect-error
145145
encoding.encodeHash = () => '#e'
146146
const router = createRouter()
147147
await router.push({ name: 'home', hash: '#%' })
@@ -151,9 +151,9 @@ describe('URL Encoding', () => {
151151
})
152152
})
153153
it('decodes hash', async () => {
154-
// @ts-ignore: override to make the difference
154+
// @ts-expect-error: override to make the difference
155155
encoding.decode = () => '#d'
156-
// @ts-ignore
156+
// @ts-expect-error
157157
encoding.encodeHash = () => '#e'
158158
const router = createRouter()
159159
await router.push('#%20')

__tests__/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export interface RouteRecordViewLoose
6060
aliasOf: RouteRecordViewLoose | undefined
6161
}
6262

63-
// @ts-ignore we are intentionally overriding the type
63+
// @ts-expect-error we are intentionally overriding the type
6464
export interface RouteLocationNormalizedLoose extends RouteLocationNormalized {
6565
name: RouteRecordName | null | undefined
6666
path: string
@@ -105,7 +105,7 @@ export function createDom(options?: ConstructorOptions) {
105105
}
106106
)
107107

108-
// @ts-ignore: needed for jsdom
108+
// @ts-expect-error: needed for jsdom
109109
global.window = dom.window
110110
global.location = dom.window.location
111111
global.history = dom.window.history

e2e/guards-instances/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function createTestComponent(key: string) {
6464
state.enter++
6565
logs.value.push(`${key}: enter ${from.path} - ${to.path}`)
6666
next(vm => {
67-
// @ts-ignore
67+
// @ts-expect-error
6868
vm.enterCallback++
6969
})
7070
},
@@ -239,7 +239,6 @@ leaves: {{ state.leave }}
239239

240240
app.use(router)
241241

242-
// @ts-ignore
243242
window.r = router
244243

245244
app.mount('#app')

e2e/modal/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,5 @@ const app = createApp({
203203
app.use(router)
204204

205205
window.vm = app.mount('#app')
206-
// @ts-ignore
206+
// @ts-expect-error
207207
window.router = router

e2e/multi-app/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ const User: RouteComponent = {
1212

1313
beforeRouteEnter(to, from, next) {
1414
next(vm => {
15-
// @ts-ignore
15+
// @ts-expect-error
1616
console.log('enter from ', vm.id)
17-
// @ts-ignore
1817
})
1918
},
2019

@@ -41,7 +40,7 @@ const NamedViews: RouteComponent[] = looper.map(i => ({
4140

4241
beforeRouteUpdate(to, from, next) {
4342
console.log('update of', i)
44-
// @ts-ignore
43+
// @ts-expect-error
4544
this.count++
4645
next()
4746
},

e2e/suspense/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ leaves: {{ state.leave }}
104104

105105
app.use(router)
106106

107-
// @ts-ignore
108107
window.r = router
109108

110109
app.mount('#app')

playground/router.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export function go(delta: number) {
257257
})
258258
}
259259

260-
// @ts-ignore
260+
// @ts-expect-error
261261
window._go = go
262262

263263
router.beforeEach((to, from, next) => {

src/RouterLink.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ function guardEvent(e: MouseEvent) {
231231
// don't redirect on right click
232232
if (e.button !== undefined && e.button !== 0) return
233233
// don't redirect if `target="_blank"`
234-
// @ts-ignore getAttribute does exist
234+
// @ts-expect-error getAttribute does exist
235235
if (e.currentTarget && e.currentTarget.getAttribute) {
236-
// @ts-ignore getAttribute exists
236+
// @ts-expect-error getAttribute exists
237237
const target = e.currentTarget.getAttribute('target')
238238
if (/\b_blank\b/i.test(target)) return
239239
}

src/devtools.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ function omit<T extends object, K extends [...(keyof T)[]]>(obj: T, keys: K) {
529529

530530
for (let key in obj) {
531531
if (!keys.includes(key as any)) {
532-
// @ts-ignore
532+
// @ts-expect-error
533533
ret[key] = obj[key]
534534
}
535535
}

src/history/memory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function createMemoryHistory(base: string = ''): RouterHistory {
103103
})
104104

105105
if (__TEST__) {
106-
// @ts-ignore: only for tests
106+
// @ts-expect-error: only for tests
107107
routerHistory.changeURL = function (url: string) {
108108
const from = this.location
109109
queue.splice(position++ + 1, queue.length, url)

src/navigationGuards.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export function guardToPromiseFn(
185185
}:\n${guard.toString()}\n. If you are returning a value instead of calling "next", make sure to remove the "next" parameter from your function.`
186186
if (typeof guardReturn === 'object' && 'then' in guardReturn) {
187187
guardCall = guardCall.then(resolvedValue => {
188-
// @ts-ignore: _called is added at canOnlyBeCalledOnce
188+
// @ts-expect-error: _called is added at canOnlyBeCalledOnce
189189
if (!next._called) {
190190
warn(message)
191191
return Promise.reject(new Error('Invalid navigation guard'))
@@ -194,7 +194,7 @@ export function guardToPromiseFn(
194194
})
195195
// TODO: test me!
196196
} else if (guardReturn !== undefined) {
197-
// @ts-ignore: _called is added at canOnlyBeCalledOnce
197+
// @ts-expect-error: _called is added at canOnlyBeCalledOnce
198198
if (!next._called) {
199199
warn(message)
200200
reject(new Error('Invalid navigation guard'))
@@ -217,7 +217,7 @@ function canOnlyBeCalledOnce(
217217
warn(
218218
`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.`
219219
)
220-
// @ts-ignore: we put it in the original one because it's easier to check
220+
// @ts-expect-error: we put it in the original one because it's easier to check
221221
next._called = true
222222
if (called === 1) next.apply(null, arguments as any)
223223
}

src/router.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,9 @@ export function createRouter(options: RouterOptions): Router {
681681
) &&
682682
// and we have done it a couple of times
683683
redirectedFrom &&
684-
// @ts-ignore
684+
// @ts-expect-error
685685
(redirectedFrom._count = redirectedFrom._count
686-
? // @ts-ignore
686+
? // @ts-expect-error
687687
redirectedFrom._count + 1
688688
: 1) > 10
689689
) {
@@ -1129,7 +1129,7 @@ export function createRouter(options: RouterOptions): Router {
11291129
>
11301130
}
11311131
for (let key in START_LOCATION_NORMALIZED) {
1132-
// @ts-ignore: the key matches
1132+
// @ts-expect-error: the key matches
11331133
reactiveRoute[key] = computed(() => currentRoute.value[key])
11341134
}
11351135

test-dts/meta.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const router = createRouter({
2626
},
2727
{
2828
path: '/foo',
29-
// @ts-ignore
29+
// @ts-expect-error
3030
component,
3131
// @ts-expect-error
3232
meta: {},

0 commit comments

Comments
 (0)