chore(types): delete @ts-ignore or use @ts-expected-error instead (#3669)

Co-authored-by: heyunfei.i <heyunfei.i@bytedance.com>
This commit is contained in:
HeYunfei 2022-05-12 08:40:59 +08:00 committed by GitHub
parent cd395559ce
commit b5b103a736
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 29 additions and 34 deletions

View File

@ -66,22 +66,22 @@ describe('reactivity/effect', () => {
it('should observe delete operations', () => {
let dummy
const obj = reactive({ prop: 'value' })
const obj = reactive<{
prop?: string
}>({ prop: 'value' })
effect(() => (dummy = obj.prop))
expect(dummy).toBe('value')
// @ts-ignore
delete obj.prop
expect(dummy).toBe(undefined)
})
it('should observe has operations', () => {
let dummy
const obj = reactive<{ prop: string | number }>({ prop: 'value' })
const obj = reactive<{ prop?: string | number }>({ prop: 'value' })
effect(() => (dummy = 'prop' in obj))
expect(dummy).toBe(true)
// @ts-ignore
delete obj.prop
expect(dummy).toBe(false)
obj.prop = 12
@ -90,13 +90,12 @@ describe('reactivity/effect', () => {
it('should observe properties on the prototype chain', () => {
let dummy
const counter = reactive({ num: 0 })
const counter = reactive<{ num?: number }>({ num: 0 })
const parentCounter = reactive({ num: 2 })
Object.setPrototypeOf(counter, parentCounter)
effect(() => (dummy = counter.num))
expect(dummy).toBe(0)
// @ts-ignore
delete counter.num
expect(dummy).toBe(2)
parentCounter.num = 4
@ -107,16 +106,14 @@ describe('reactivity/effect', () => {
it('should observe has operations on the prototype chain', () => {
let dummy
const counter = reactive({ num: 0 })
const parentCounter = reactive({ num: 2 })
const counter = reactive<{ num?: number }>({ num: 0 })
const parentCounter = reactive<{ num?: number }>({ num: 2 })
Object.setPrototypeOf(counter, parentCounter)
effect(() => (dummy = 'num' in counter))
expect(dummy).toBe(true)
// @ts-ignore
delete counter.num
expect(dummy).toBe(true)
// @ts-ignore
delete parentCounter.num
expect(dummy).toBe(false)
counter.num = 3
@ -220,7 +217,7 @@ describe('reactivity/effect', () => {
it('should observe symbol keyed properties', () => {
const key = Symbol('symbol keyed prop')
let dummy, hasDummy
const obj = reactive({ [key]: 'value' })
const obj = reactive<{ [key]?: string }>({ [key]: 'value' })
effect(() => (dummy = obj[key]))
effect(() => (hasDummy = key in obj))
@ -228,7 +225,6 @@ describe('reactivity/effect', () => {
expect(hasDummy).toBe(true)
obj[key] = 'newValue'
expect(dummy).toBe('newValue')
// @ts-ignore
delete obj[key]
expect(dummy).toBe(undefined)
expect(hasDummy).toBe(false)
@ -752,7 +748,7 @@ describe('reactivity/effect', () => {
const onTrigger = jest.fn((e: DebuggerEvent) => {
events.push(e)
})
const obj = reactive({ foo: 1 })
const obj = reactive<{ foo?: number }>({ foo: 1 })
const runner = effect(
() => {
dummy = obj.foo
@ -760,7 +756,7 @@ describe('reactivity/effect', () => {
{ onTrigger }
)
obj.foo++
obj.foo!++
expect(dummy).toBe(2)
expect(onTrigger).toHaveBeenCalledTimes(1)
expect(events[0]).toEqual({
@ -772,7 +768,6 @@ describe('reactivity/effect', () => {
newValue: 2
})
// @ts-ignore
delete obj.foo
expect(dummy).toBeUndefined()
expect(onTrigger).toHaveBeenCalledTimes(2)

View File

@ -112,14 +112,13 @@ describe('reactivity/reactive/Array', () => {
})
test('add non-integer prop on Array should not trigger length dependency', () => {
const array = new Array(3)
const array: any[] & { x?: string } = new Array(3)
const observed = reactive(array)
const fn = jest.fn()
effect(() => {
fn(observed.length)
})
expect(fn).toHaveBeenCalledTimes(1)
// @ts-ignore
observed.x = 'x'
expect(fn).toHaveBeenCalledTimes(1)
observed[-1] = 'x'

View File

@ -68,21 +68,21 @@ describe('reactivity/readonly', () => {
`Set operation on key "Symbol(qux)" failed: target is readonly.`
).toHaveBeenWarnedLast()
// @ts-ignore
// @ts-expect-error
delete wrapped.foo
expect(wrapped.foo).toBe(1)
expect(
`Delete operation on key "foo" failed: target is readonly.`
).toHaveBeenWarnedLast()
// @ts-ignore
// @ts-expect-error
delete wrapped.bar.baz
expect(wrapped.bar.baz).toBe(2)
expect(
`Delete operation on key "baz" failed: target is readonly.`
).toHaveBeenWarnedLast()
// @ts-ignore
// @ts-expect-error
delete wrapped[qux]
expect(wrapped[qux]).toBe(3)
expect(

View File

@ -8,7 +8,7 @@ describe('reactivity/shallowReadonly', () => {
test('should make root level properties readonly', () => {
const props = shallowReadonly({ n: 1 })
// @ts-ignore
// @ts-expect-error
props.n = 2
expect(props.n).toBe(1)
expect(
@ -19,7 +19,7 @@ describe('reactivity/shallowReadonly', () => {
// to retain 2.x behavior.
test('should NOT make nested properties readonly', () => {
const props = shallowReadonly({ n: { foo: 1 } })
// @ts-ignore
props.n.foo = 2
expect(props.n.foo).toBe(2)
expect(

View File

@ -334,7 +334,10 @@ describe('api: lifecycle hooks', () => {
const onTrigger = jest.fn((e: DebuggerEvent) => {
events.push(e)
})
const obj = reactive({ foo: 1, bar: 2 })
const obj = reactive<{
foo: number
bar?: number
}>({ foo: 1, bar: 2 })
const Comp = {
setup() {
@ -356,7 +359,6 @@ describe('api: lifecycle hooks', () => {
newValue: 2
})
// @ts-ignore
delete obj.bar
await nextTick()
expect(onTrigger).toHaveBeenCalledTimes(2)

View File

@ -1411,7 +1411,7 @@ describe('api: options', () => {
}
const root = nodeOps.createElement('div')
// @ts-ignore
// @ts-expect-error
render(h(Comp), root)
expect('Invalid watch option: "foo"').toHaveBeenWarned()

View File

@ -214,7 +214,7 @@ describe('api: watch', () => {
})
it('warn invalid watch source', () => {
// @ts-ignore
// @ts-expect-error
watch(1, () => {})
expect(`Invalid watch source`).toHaveBeenWarned()
})
@ -748,7 +748,7 @@ describe('api: watch', () => {
() => {
dummy = count.value
},
// @ts-ignore
// @ts-expect-error
{ immediate: false }
)
expect(dummy).toBe(0)
@ -767,7 +767,7 @@ describe('api: watch', () => {
spy()
return arr
},
// @ts-ignore
// @ts-expect-error
{ deep: true }
)
expect(spy).toHaveBeenCalledTimes(1)
@ -818,7 +818,7 @@ describe('api: watch', () => {
const onTrigger = jest.fn((e: DebuggerEvent) => {
events.push(e)
})
const obj = reactive({ foo: 1 })
const obj = reactive<{ foo?: number }>({ foo: 1 })
watchEffect(
() => {
dummy = obj.foo
@ -828,7 +828,7 @@ describe('api: watch', () => {
await nextTick()
expect(dummy).toBe(1)
obj.foo++
obj.foo!++
await nextTick()
expect(dummy).toBe(2)
expect(onTrigger).toHaveBeenCalledTimes(1)
@ -839,7 +839,6 @@ describe('api: watch', () => {
newValue: 2
})
// @ts-ignore
delete obj.foo
await nextTick()
expect(dummy).toBeUndefined()

View File

@ -153,7 +153,7 @@ describe('component: emit', () => {
emits: ['foo'],
render() {},
created() {
// @ts-ignore
// @ts-expect-error
this.$emit('bar')
}
})
@ -170,7 +170,7 @@ describe('component: emit', () => {
},
render() {},
created() {
// @ts-ignore
// @ts-expect-error
this.$emit('bar')
}
})
@ -186,7 +186,7 @@ describe('component: emit', () => {
emits: [],
render() {},
created() {
// @ts-ignore
// @ts-expect-error
this.$emit('foo')
}
})