]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore: remove unnecessary type assertions (#8311)
author丶远方 <yangpanteng@gmail.com>
Thu, 18 May 2023 23:49:28 +0000 (07:49 +0800)
committerGitHub <noreply@github.com>
Thu, 18 May 2023 23:49:28 +0000 (07:49 +0800)
packages/reactivity/src/ref.ts
packages/runtime-core/src/apiAsyncComponent.ts
packages/runtime-core/src/apiComputed.ts
packages/runtime-core/src/apiCreateApp.ts
packages/runtime-core/src/apiWatch.ts
packages/runtime-core/src/component.ts
packages/runtime-core/src/componentEmits.ts
packages/runtime-core/src/componentOptions.ts
packages/runtime-core/src/componentPublicInstance.ts
packages/runtime-core/src/hmr.ts

index a5224d7f28171a09dd46da87816f63f5707ff0c8..60de3ae20281ab4c930be733be1b7e0bf5800dd6 100644 (file)
@@ -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<string, any>,
+  key: string,
+  defaultValue?: unknown
+) {
+  const val = source[key]
   return isRef(val)
     ? val
-    : (new ObjectRefImpl(
-        source as Record<string, any>,
-        key,
-        defaultValue
-      ) as any)
+    : (new ObjectRefImpl(source, key, defaultValue) as any)
 }
 
 // corner case when use narrows type
index 09a857bc08b5a06e8d5c4c3e30f9873f18563c48..bd878a494425d8ab1c4587510e6c6e11c401027d 100644 (file)
@@ -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)
         }
       }
     }
index 3804531bd44a9f5f6393093fa9b786e0c7a94dda..1cd9c2ec21815e5ff1d4313857e0bbef484d2c5b 100644 (file)
@@ -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
+}
index 15f7766f32308132767256fe56a48d47b8addd86..ec45611ddf8cd4d76bf0f75dd89d4fa057700528 100644 (file)
@@ -330,10 +330,7 @@ export function createAppAPI<HostElement>(
                 ` 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
index 631299fdc576f23ab49ca7ac645d811c123bce2e..1b85ba12d19b66586a38e10cb144f18f57758799 100644 (file)
@@ -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<unknown>) {
     })
   } else if (isPlainObject(value)) {
     for (const key in value) {
-      traverse((value as any)[key], seen)
+      traverse(value[key], seen)
     }
   }
   return value
index 33229630e49b2fd71c980bf6756215a834cf00f4..7048dc076856dc6a1f439063bba6cb7ceb315515 100644 (file)
@@ -161,7 +161,7 @@ export type ConcreteComponent<
   M extends MethodOptions = MethodOptions
 > =
   | ComponentOptions<Props, RawBindings, D, C, M>
-  | FunctionalComponent<Props, any, any>
+  | FunctionalComponent<Props, any>
 
 /**
  * A type used in public APIs where a component type is expected.
index 7568741e24e8d154ef80fafda725704042bc0ce8..1bf122541d6abe6bc1daf008fd558e5ea411281c 100644 (file)
@@ -173,7 +173,7 @@ export function emit(
   const onceHandler = props[handlerName + `Once`]
   if (onceHandler) {
     if (!instance.emitted) {
-      instance.emitted = {} as Record<any, boolean>
+      instance.emitted = {}
     } else if (instance.emitted[handlerName]) {
       return
     }
index 527686596359da0f47a672fd2375148968a25d5c..de4d304448a73f48f7342a3efeb23899303ec090 100644 (file)
@@ -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) {
index 79bcedda75917013dd6ca1d27a29a4b175fbffb7..78a9acd147fddc9946dbdea5773a7252ec5e30c0 100644 (file)
@@ -105,7 +105,7 @@ type ExtractMixin<T> = {
 }[T extends ComponentOptionsMixin ? 'Mixin' : never]
 
 export type IntersectionMixin<T> = IsDefaultMixinComponent<T> extends true
-  ? OptionTypesType<{}, {}, {}, {}, {}>
+  ? OptionTypesType
   : UnionToIntersection<ExtractMixin<T>>
 
 export type UnwrapMixinsType<
index fe8ca132bc8b2177ba58acce271e5dedefc65225..1ce66a3da1ec69c194f7d19051f3e2b797317771 100644 (file)
@@ -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]
     }
   }
 }