Skip to content

Commit

Permalink
style: refactor using ts-expect-error
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed May 14, 2021
1 parent 1227828 commit a68a39e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions __tests__/hash-manual-navigation.spec.ts
@@ -1,17 +1,15 @@
import { createMemoryHistory, createRouter } from '../src'
import { createMemoryHistory, createRouter, RouterHistory } from '../src'
import { tick } from './utils'

const component = {}

declare module '../src' {
export interface RouterHistory {
changeURL(url: string): void
}
interface RouterHistory_Test extends RouterHistory {
changeURL(url: string): void
}

describe('hash history edge cases', () => {
it('correctly sets the url when it is manually changed but aborted with a redirect in guard', async () => {
const history = createMemoryHistory()
const history = createMemoryHistory() as RouterHistory_Test
const router = createRouter({
history,
routes: [
Expand All @@ -30,8 +28,10 @@ describe('hash history edge cases', () => {
// force a redirect next time
const removeListener = router.beforeEach(to => {
if (to.path === '/') {
removeListener()
return '/foo?step=2'
}
return
})

// const spy = jest.spyOn(history, 'go')
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 @@ -678,9 +678,9 @@ export function createRouter(options: RouterOptions): Router {
) &&
// and we have done it a couple of times
redirectedFrom &&
// @ts-ignore
// @ts-expect-error: added only in dev
(redirectedFrom._count = redirectedFrom._count
? // @ts-ignore
? // @ts-expect-error
redirectedFrom._count + 1
: 1) > 10
) {
Expand Down Expand Up @@ -1157,7 +1157,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

0 comments on commit a68a39e

Please sign in to comment.