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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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