Просмотр исходного кода

chore: remove unnecessary type assertions (#8311)

丶远方 2 лет назад
Родитель
Сommit
3798c5480b

+ 7 - 7
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<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

+ 2 - 2
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)
         }
       }
     }

+ 5 - 2
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
+}

+ 1 - 4
packages/runtime-core/src/apiCreateApp.ts

@@ -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

+ 3 - 6
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<unknown>) {
     })
   } else if (isPlainObject(value)) {
     for (const key in value) {
-      traverse((value as any)[key], seen)
+      traverse(value[key], seen)
     }
   }
   return value

+ 1 - 1
packages/runtime-core/src/component.ts

@@ -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.

+ 1 - 1
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<any, boolean>
+      instance.emitted = {}
     } else if (instance.emitted[handlerName]) {
       return
     }

+ 2 - 2
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) {

+ 1 - 1
packages/runtime-core/src/componentPublicInstance.ts

@@ -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<

+ 1 - 1
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]
     }
   }
 }