From: 丶远方 Date: Thu, 18 May 2023 23:49:28 +0000 (+0800) Subject: chore: remove unnecessary type assertions (#8311) X-Git-Tag: v3.3.5~124 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3798c5480b8ed186a279d21d3abe95d400cdbaaf;p=thirdparty%2Fvuejs%2Fcore.git chore: remove unnecessary type assertions (#8311) --- diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index a5224d7f28..60de3ae202 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -440,15 +440,15 @@ export function toRef( } } -function propertyToRef(source: object, key: string, defaultValue?: unknown) { - const val = (source as any)[key] +function propertyToRef( + source: Record, + key: string, + defaultValue?: unknown +) { + const val = source[key] return isRef(val) ? val - : (new ObjectRefImpl( - source as Record, - key, - defaultValue - ) as any) + : (new ObjectRefImpl(source, key, defaultValue) as any) } // corner case when use narrows type diff --git a/packages/runtime-core/src/apiAsyncComponent.ts b/packages/runtime-core/src/apiAsyncComponent.ts index 09a857bc08..bd878a4944 100644 --- a/packages/runtime-core/src/apiAsyncComponent.ts +++ b/packages/runtime-core/src/apiAsyncComponent.ts @@ -198,11 +198,11 @@ export function defineAsyncComponent< if (loaded.value && resolvedComp) { return createInnerComp(resolvedComp, instance) } else if (error.value && errorComponent) { - return createVNode(errorComponent as ConcreteComponent, { + return createVNode(errorComponent, { error: error.value }) } else if (loadingComponent && !delayed.value) { - return createVNode(loadingComponent as ConcreteComponent) + return createVNode(loadingComponent) } } } diff --git a/packages/runtime-core/src/apiComputed.ts b/packages/runtime-core/src/apiComputed.ts index 3804531bd4..1cd9c2ec21 100644 --- a/packages/runtime-core/src/apiComputed.ts +++ b/packages/runtime-core/src/apiComputed.ts @@ -1,7 +1,10 @@ import { computed as _computed } from '@vue/reactivity' import { isInSSRComponentSetup } from './component' -export const computed = ((getterOrOptions: any, debugOptions?: any) => { +export const computed: typeof _computed = ( + getterOrOptions: any, + debugOptions?: any +) => { // @ts-ignore return _computed(getterOrOptions, debugOptions, isInSSRComponentSetup) -}) as typeof _computed +} diff --git a/packages/runtime-core/src/apiCreateApp.ts b/packages/runtime-core/src/apiCreateApp.ts index 15f7766f32..ec45611ddf 100644 --- a/packages/runtime-core/src/apiCreateApp.ts +++ b/packages/runtime-core/src/apiCreateApp.ts @@ -330,10 +330,7 @@ export function createAppAPI( ` you need to unmount the previous app by calling \`app.unmount()\` first.` ) } - const vnode = createVNode( - rootComponent as ConcreteComponent, - rootProps - ) + const vnode = createVNode(rootComponent, rootProps) // store app context on the root VNode. // this will be set on the root instance on initial mount. vnode.appContext = context diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 631299fdc5..1b85ba12d1 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -43,7 +43,6 @@ import { DeprecationTypes } from './compat/compatConfig' import { checkCompatEnabled, isCompatEnabled } from './compat/compatConfig' import { ObjectWatchOptionItem } from './componentOptions' import { useSSRContext } from '@vue/runtime-core' -import { SSRContext } from '@vue/server-renderer' export type WatchEffect = (onCleanup: OnCleanup) => void @@ -297,7 +296,7 @@ function doWatch( ]) } if (flush === 'sync') { - const ctx = useSSRContext() as SSRContext + const ctx = useSSRContext()! ssrCleanup = ctx.__watcherHandles || (ctx.__watcherHandles = []) } else { return NOOP @@ -318,9 +317,7 @@ function doWatch( deep || forceTrigger || (isMultiSource - ? (newValue as any[]).some((v, i) => - hasChanged(v, (oldValue as any[])[i]) - ) + ? (newValue as any[]).some((v, i) => hasChanged(v, oldValue[i])) : hasChanged(newValue, oldValue)) || (__COMPAT__ && isArray(newValue) && @@ -461,7 +458,7 @@ export function traverse(value: unknown, seen?: 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/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index 33229630e4..7048dc0768 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -161,7 +161,7 @@ export type ConcreteComponent< M extends MethodOptions = MethodOptions > = | ComponentOptions - | FunctionalComponent + | FunctionalComponent /** * A type used in public APIs where a component type is expected. diff --git a/packages/runtime-core/src/componentEmits.ts b/packages/runtime-core/src/componentEmits.ts index 7568741e24..1bf122541d 100644 --- a/packages/runtime-core/src/componentEmits.ts +++ b/packages/runtime-core/src/componentEmits.ts @@ -173,7 +173,7 @@ export function emit( const onceHandler = props[handlerName + `Once`] if (onceHandler) { if (!instance.emitted) { - instance.emitted = {} as Record + instance.emitted = {} } else if (instance.emitted[handlerName]) { return } diff --git a/packages/runtime-core/src/componentOptions.ts b/packages/runtime-core/src/componentOptions.ts index 5276865963..de4d304448 100644 --- a/packages/runtime-core/src/componentOptions.ts +++ b/packages/runtime-core/src/componentOptions.ts @@ -809,7 +809,7 @@ export function applyOptions(instance: ComponentInternalInstance) { if (isArray(hook)) { hook.forEach(_hook => register(_hook.bind(publicThis))) } else if (hook) { - register((hook as Function).bind(publicThis)) + register(hook.bind(publicThis)) } } @@ -885,7 +885,7 @@ export function resolveInjections( injectOptions = normalizeInject(injectOptions)! } for (const key in injectOptions) { - const opt = (injectOptions as ObjectInjectOptions)[key] + const opt = injectOptions[key] let injected: unknown if (isObject(opt)) { if ('default' in opt) { diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index 79bcedda75..78a9acd147 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -105,7 +105,7 @@ type ExtractMixin = { }[T extends ComponentOptionsMixin ? 'Mixin' : never] export type IntersectionMixin = IsDefaultMixinComponent extends true - ? OptionTypesType<{}, {}, {}, {}, {}> + ? OptionTypesType : UnionToIntersection> export type UnwrapMixinsType< diff --git a/packages/runtime-core/src/hmr.ts b/packages/runtime-core/src/hmr.ts index fe8ca132bc..1ce66a3da1 100644 --- a/packages/runtime-core/src/hmr.ts +++ b/packages/runtime-core/src/hmr.ts @@ -168,7 +168,7 @@ function updateComponentDef( extend(oldComp, newComp) for (const key in oldComp) { if (key !== '__file' && !(key in newComp)) { - delete (oldComp as any)[key] + delete oldComp[key] } } }