From ebb7975da2945034aaeec3c3a344aa69330ebc9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?null=E4=BB=94?= <308241863@qq.com> Date: Fri, 16 Jul 2021 16:37:20 +0800 Subject: [PATCH] fix(type): remove unnecessary type assertion (#766) Co-authored-by: webfansplz <> --- src/apis/createElement.ts | 2 +- src/apis/lifecycle.ts | 2 +- src/apis/nextTick.ts | 2 +- src/apis/watch.ts | 4 ++-- src/reactivity/reactive.ts | 8 ++++---- src/reactivity/ref.ts | 2 +- src/runtimeContext.ts | 6 +++--- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/apis/createElement.ts b/src/apis/createElement.ts index 6e05d9db..6302405e 100644 --- a/src/apis/createElement.ts +++ b/src/apis/createElement.ts @@ -22,4 +22,4 @@ export const createElement = function createElement(...args: any) { } return instance.$createElement.apply(instance, args) -} as any as CreateElement +} as CreateElement diff --git a/src/apis/lifecycle.ts b/src/apis/lifecycle.ts index 32b05f39..55cb951d 100644 --- a/src/apis/lifecycle.ts +++ b/src/apis/lifecycle.ts @@ -23,7 +23,7 @@ function injectHookOption( hook: string, val: Function ) { - const options = vm.$options as any + const options = vm.$options as Record const mergeFn = Vue.config.optionMergeStrategies[hook] options[hook] = mergeFn(options[hook], wrapHookCall(vm, val)) } diff --git a/src/apis/nextTick.ts b/src/apis/nextTick.ts index cb82c111..9c736ef9 100644 --- a/src/apis/nextTick.ts +++ b/src/apis/nextTick.ts @@ -8,4 +8,4 @@ export const nextTick: NextTick = function nextTick( ...args: Parameters ) { return getVueConstructor()?.nextTick.apply(this, args) -} as any +} diff --git a/src/apis/watch.ts b/src/apis/watch.ts index 5073a603..8f8ce5d6 100644 --- a/src/apis/watch.ts +++ b/src/apis/watch.ts @@ -255,7 +255,7 @@ function createWatcher( fn(...args) }, flushMode as 'pre' | 'post' - )) as any as T + )) as unknown as T } // effect watch @@ -471,7 +471,7 @@ function traverse(value: unknown, seen: Set = new Set()) { }) } else if (isPlainObject(value)) { for (const key in value) { - traverse((value as any)[key], seen) + traverse(value[key], seen) } } return value diff --git a/src/reactivity/reactive.ts b/src/reactivity/reactive.ts index 2914d1e8..7599ab68 100644 --- a/src/reactivity/reactive.ts +++ b/src/reactivity/reactive.ts @@ -171,12 +171,12 @@ export function createObserver() { } export function shallowReactive(obj: T): T -export function shallowReactive(obj: any): any { +export function shallowReactive(obj: any) { if (!isObject(obj)) { if (__DEV__) { warn('"shallowReactive()" must be called on an object.') } - return obj as any + return obj } if ( @@ -184,7 +184,7 @@ export function shallowReactive(obj: any): any { isRaw(obj) || !Object.isExtensible(obj) ) { - return obj as any + return obj } const observed = observe(isArray(obj) ? [] : {}) @@ -233,7 +233,7 @@ export function reactive(obj: T): UnwrapRef { if (__DEV__) { warn('"reactive()" must be called on an object.') } - return obj as any + return obj } if ( diff --git a/src/reactivity/ref.ts b/src/reactivity/ref.ts index 32c187d1..14c7b652 100644 --- a/src/reactivity/ref.ts +++ b/src/reactivity/ref.ts @@ -122,7 +122,7 @@ export function toRefs(obj: T): ToRefs { if (__DEV__ && !isReactive(obj)) { warn(`toRefs() expects a reactive object but received a plain one.`) } - if (!isPlainObject(obj)) return obj as any + if (!isPlainObject(obj)) return obj const ret: any = {} for (const key in obj) { diff --git a/src/runtimeContext.ts b/src/runtimeContext.ts index 64e2a65b..bfdd68da 100644 --- a/src/runtimeContext.ts +++ b/src/runtimeContext.ts @@ -168,7 +168,7 @@ function toVue3ComponentInstance( return instanceMapCache.get(vue2Instance)! } - const instance: ComponentInternalInstance = ({ + const instance: ComponentInternalInstance = { proxy: vue2Instance, update: vue2Instance.$forceUpdate, uid: vue2Instance._uid, @@ -177,8 +177,8 @@ function toVue3ComponentInstance( emit: vue2Instance.$emit.bind(vue2Instance), parent: null, - root: null as any, - } as unknown) as ComponentInternalInstance + root: null!, // to be immediately set + } as unknown as ComponentInternalInstance // map vm.$props = const instanceProps = [