mirror of https://github.com/vuejs/core.git
chore: remove unnecessary type assertions (#8311)
This commit is contained in:
parent
5ddeb45e82
commit
3798c5480b
|
@ -440,15 +440,15 @@ export function toRef(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function propertyToRef(source: object, key: string, defaultValue?: unknown) {
|
function propertyToRef(
|
||||||
const val = (source as any)[key]
|
source: Record<string, any>,
|
||||||
|
key: string,
|
||||||
|
defaultValue?: unknown
|
||||||
|
) {
|
||||||
|
const val = source[key]
|
||||||
return isRef(val)
|
return isRef(val)
|
||||||
? val
|
? val
|
||||||
: (new ObjectRefImpl(
|
: (new ObjectRefImpl(source, key, defaultValue) as any)
|
||||||
source as Record<string, any>,
|
|
||||||
key,
|
|
||||||
defaultValue
|
|
||||||
) as any)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// corner case when use narrows type
|
// corner case when use narrows type
|
||||||
|
|
|
@ -198,11 +198,11 @@ export function defineAsyncComponent<
|
||||||
if (loaded.value && resolvedComp) {
|
if (loaded.value && resolvedComp) {
|
||||||
return createInnerComp(resolvedComp, instance)
|
return createInnerComp(resolvedComp, instance)
|
||||||
} else if (error.value && errorComponent) {
|
} else if (error.value && errorComponent) {
|
||||||
return createVNode(errorComponent as ConcreteComponent, {
|
return createVNode(errorComponent, {
|
||||||
error: error.value
|
error: error.value
|
||||||
})
|
})
|
||||||
} else if (loadingComponent && !delayed.value) {
|
} else if (loadingComponent && !delayed.value) {
|
||||||
return createVNode(loadingComponent as ConcreteComponent)
|
return createVNode(loadingComponent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import { computed as _computed } from '@vue/reactivity'
|
import { computed as _computed } from '@vue/reactivity'
|
||||||
import { isInSSRComponentSetup } from './component'
|
import { isInSSRComponentSetup } from './component'
|
||||||
|
|
||||||
export const computed = ((getterOrOptions: any, debugOptions?: any) => {
|
export const computed: typeof _computed = (
|
||||||
|
getterOrOptions: any,
|
||||||
|
debugOptions?: any
|
||||||
|
) => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return _computed(getterOrOptions, debugOptions, isInSSRComponentSetup)
|
return _computed(getterOrOptions, debugOptions, isInSSRComponentSetup)
|
||||||
}) as typeof _computed
|
}
|
||||||
|
|
|
@ -330,10 +330,7 @@ export function createAppAPI<HostElement>(
|
||||||
` you need to unmount the previous app by calling \`app.unmount()\` first.`
|
` you need to unmount the previous app by calling \`app.unmount()\` first.`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
const vnode = createVNode(
|
const vnode = createVNode(rootComponent, rootProps)
|
||||||
rootComponent as ConcreteComponent,
|
|
||||||
rootProps
|
|
||||||
)
|
|
||||||
// store app context on the root VNode.
|
// store app context on the root VNode.
|
||||||
// this will be set on the root instance on initial mount.
|
// this will be set on the root instance on initial mount.
|
||||||
vnode.appContext = context
|
vnode.appContext = context
|
||||||
|
|
|
@ -43,7 +43,6 @@ import { DeprecationTypes } from './compat/compatConfig'
|
||||||
import { checkCompatEnabled, isCompatEnabled } from './compat/compatConfig'
|
import { checkCompatEnabled, isCompatEnabled } from './compat/compatConfig'
|
||||||
import { ObjectWatchOptionItem } from './componentOptions'
|
import { ObjectWatchOptionItem } from './componentOptions'
|
||||||
import { useSSRContext } from '@vue/runtime-core'
|
import { useSSRContext } from '@vue/runtime-core'
|
||||||
import { SSRContext } from '@vue/server-renderer'
|
|
||||||
|
|
||||||
export type WatchEffect = (onCleanup: OnCleanup) => void
|
export type WatchEffect = (onCleanup: OnCleanup) => void
|
||||||
|
|
||||||
|
@ -297,7 +296,7 @@ function doWatch(
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
if (flush === 'sync') {
|
if (flush === 'sync') {
|
||||||
const ctx = useSSRContext() as SSRContext
|
const ctx = useSSRContext()!
|
||||||
ssrCleanup = ctx.__watcherHandles || (ctx.__watcherHandles = [])
|
ssrCleanup = ctx.__watcherHandles || (ctx.__watcherHandles = [])
|
||||||
} else {
|
} else {
|
||||||
return NOOP
|
return NOOP
|
||||||
|
@ -318,9 +317,7 @@ function doWatch(
|
||||||
deep ||
|
deep ||
|
||||||
forceTrigger ||
|
forceTrigger ||
|
||||||
(isMultiSource
|
(isMultiSource
|
||||||
? (newValue as any[]).some((v, i) =>
|
? (newValue as any[]).some((v, i) => hasChanged(v, oldValue[i]))
|
||||||
hasChanged(v, (oldValue as any[])[i])
|
|
||||||
)
|
|
||||||
: hasChanged(newValue, oldValue)) ||
|
: hasChanged(newValue, oldValue)) ||
|
||||||
(__COMPAT__ &&
|
(__COMPAT__ &&
|
||||||
isArray(newValue) &&
|
isArray(newValue) &&
|
||||||
|
@ -461,7 +458,7 @@ export function traverse(value: unknown, seen?: Set<unknown>) {
|
||||||
})
|
})
|
||||||
} else if (isPlainObject(value)) {
|
} else if (isPlainObject(value)) {
|
||||||
for (const key in value) {
|
for (const key in value) {
|
||||||
traverse((value as any)[key], seen)
|
traverse(value[key], seen)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -161,7 +161,7 @@ export type ConcreteComponent<
|
||||||
M extends MethodOptions = MethodOptions
|
M extends MethodOptions = MethodOptions
|
||||||
> =
|
> =
|
||||||
| ComponentOptions<Props, RawBindings, D, C, M>
|
| 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.
|
* A type used in public APIs where a component type is expected.
|
||||||
|
|
|
@ -173,7 +173,7 @@ export function emit(
|
||||||
const onceHandler = props[handlerName + `Once`]
|
const onceHandler = props[handlerName + `Once`]
|
||||||
if (onceHandler) {
|
if (onceHandler) {
|
||||||
if (!instance.emitted) {
|
if (!instance.emitted) {
|
||||||
instance.emitted = {} as Record<any, boolean>
|
instance.emitted = {}
|
||||||
} else if (instance.emitted[handlerName]) {
|
} else if (instance.emitted[handlerName]) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -809,7 +809,7 @@ export function applyOptions(instance: ComponentInternalInstance) {
|
||||||
if (isArray(hook)) {
|
if (isArray(hook)) {
|
||||||
hook.forEach(_hook => register(_hook.bind(publicThis)))
|
hook.forEach(_hook => register(_hook.bind(publicThis)))
|
||||||
} else if (hook) {
|
} else if (hook) {
|
||||||
register((hook as Function).bind(publicThis))
|
register(hook.bind(publicThis))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -885,7 +885,7 @@ export function resolveInjections(
|
||||||
injectOptions = normalizeInject(injectOptions)!
|
injectOptions = normalizeInject(injectOptions)!
|
||||||
}
|
}
|
||||||
for (const key in injectOptions) {
|
for (const key in injectOptions) {
|
||||||
const opt = (injectOptions as ObjectInjectOptions)[key]
|
const opt = injectOptions[key]
|
||||||
let injected: unknown
|
let injected: unknown
|
||||||
if (isObject(opt)) {
|
if (isObject(opt)) {
|
||||||
if ('default' in opt) {
|
if ('default' in opt) {
|
||||||
|
|
|
@ -105,7 +105,7 @@ type ExtractMixin<T> = {
|
||||||
}[T extends ComponentOptionsMixin ? 'Mixin' : never]
|
}[T extends ComponentOptionsMixin ? 'Mixin' : never]
|
||||||
|
|
||||||
export type IntersectionMixin<T> = IsDefaultMixinComponent<T> extends true
|
export type IntersectionMixin<T> = IsDefaultMixinComponent<T> extends true
|
||||||
? OptionTypesType<{}, {}, {}, {}, {}>
|
? OptionTypesType
|
||||||
: UnionToIntersection<ExtractMixin<T>>
|
: UnionToIntersection<ExtractMixin<T>>
|
||||||
|
|
||||||
export type UnwrapMixinsType<
|
export type UnwrapMixinsType<
|
||||||
|
|
|
@ -168,7 +168,7 @@ function updateComponentDef(
|
||||||
extend(oldComp, newComp)
|
extend(oldComp, newComp)
|
||||||
for (const key in oldComp) {
|
for (const key in oldComp) {
|
||||||
if (key !== '__file' && !(key in newComp)) {
|
if (key !== '__file' && !(key in newComp)) {
|
||||||
delete (oldComp as any)[key]
|
delete oldComp[key]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue