Skip to content

Commit

Permalink
refactor: use ts-expect-error
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Jun 1, 2021
1 parent 3d465cc commit 20f4580
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 49 deletions.
4 changes: 2 additions & 2 deletions __tests__/RouterLink.spec.ts
Expand Up @@ -919,15 +919,15 @@ describe('RouterLink', () => {
components: { RouterLink },
name: 'AppLink',

// @ts-ignore
// @ts-expect-error
props: {
...((RouterLink as any).props as RouterLinkProps),
inactiveClass: String as PropType<string>,
},

computed: {
isExternalLink(): boolean {
// @ts-ignore
// @ts-expect-error
return typeof this.to === 'string' && this.to.startsWith('http')
},
},
Expand Down
5 changes: 2 additions & 3 deletions __tests__/guards/extractComponentsGuards.spec.ts
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion __tests__/matcher/addingRemoving.spec.ts
Expand Up @@ -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', () => {
Expand Down
6 changes: 2 additions & 4 deletions __tests__/matcher/pathRanking.spec.ts
Expand Up @@ -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: [],
}
Expand Down
6 changes: 2 additions & 4 deletions __tests__/matcher/resolve.spec.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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 => ({
Expand Down
2 changes: 1 addition & 1 deletion __tests__/mount.ts
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion __tests__/router.spec.ts
Expand Up @@ -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'
)
Expand Down
24 changes: 12 additions & 12 deletions __tests__/urlEncoding.spec.ts
Expand Up @@ -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
}
})
Expand Down Expand Up @@ -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%' } })
Expand Down Expand Up @@ -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: '%' } })
Expand All @@ -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: '#%' })
Expand All @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions __tests__/utils.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions e2e/guards-instances/index.ts
Expand Up @@ -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++
})
},
Expand Down Expand Up @@ -239,7 +239,6 @@ leaves: {{ state.leave }}

app.use(router)

// @ts-ignore
window.r = router

app.mount('#app')
2 changes: 1 addition & 1 deletion e2e/modal/index.ts
Expand Up @@ -203,5 +203,5 @@ const app = createApp({
app.use(router)

window.vm = app.mount('#app')
// @ts-ignore
// @ts-expect-error
window.router = router
5 changes: 2 additions & 3 deletions e2e/multi-app/index.ts
Expand Up @@ -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
})
},

Expand All @@ -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()
},
Expand Down
1 change: 0 additions & 1 deletion e2e/suspense/index.ts
Expand Up @@ -104,7 +104,6 @@ leaves: {{ state.leave }}

app.use(router)

// @ts-ignore
window.r = router

app.mount('#app')
2 changes: 1 addition & 1 deletion playground/router.ts
Expand Up @@ -257,7 +257,7 @@ export function go(delta: number) {
})
}

// @ts-ignore
// @ts-expect-error
window._go = go

router.beforeEach((to, from, next) => {
Expand Down
4 changes: 2 additions & 2 deletions src/RouterLink.ts
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/devtools.ts
Expand Up @@ -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]
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/history/memory.ts
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/navigationGuards.ts
Expand Up @@ -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'))
Expand All @@ -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'))
Expand All @@ -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)
}
Expand Down
6 changes: 3 additions & 3 deletions src/router.ts
Expand Up @@ -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
) {
Expand Down Expand Up @@ -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])
}

Expand Down
2 changes: 1 addition & 1 deletion test-dts/meta.test-d.ts
Expand Up @@ -26,7 +26,7 @@ const router = createRouter({
},
{
path: '/foo',
// @ts-ignore
// @ts-expect-error
component,
// @ts-expect-error
meta: {},
Expand Down

0 comments on commit 20f4580

Please sign in to comment.