Skip to content

Commit 3798c54

Browse files
chore: remove unnecessary type assertions (#8311)
1 parent 5ddeb45 commit 3798c54

File tree

10 files changed

+24
-27
lines changed

10 files changed

+24
-27
lines changed

packages/reactivity/src/ref.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,15 +440,15 @@ export function toRef(
440440
}
441441
}
442442

443-
function propertyToRef(source: object, key: string, defaultValue?: unknown) {
444-
const val = (source as any)[key]
443+
function propertyToRef(
444+
source: Record<string, any>,
445+
key: string,
446+
defaultValue?: unknown
447+
) {
448+
const val = source[key]
445449
return isRef(val)
446450
? val
447-
: (new ObjectRefImpl(
448-
source as Record<string, any>,
449-
key,
450-
defaultValue
451-
) as any)
451+
: (new ObjectRefImpl(source, key, defaultValue) as any)
452452
}
453453

454454
// corner case when use narrows type

packages/runtime-core/src/apiAsyncComponent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ export function defineAsyncComponent<
198198
if (loaded.value && resolvedComp) {
199199
return createInnerComp(resolvedComp, instance)
200200
} else if (error.value && errorComponent) {
201-
return createVNode(errorComponent as ConcreteComponent, {
201+
return createVNode(errorComponent, {
202202
error: error.value
203203
})
204204
} else if (loadingComponent && !delayed.value) {
205-
return createVNode(loadingComponent as ConcreteComponent)
205+
return createVNode(loadingComponent)
206206
}
207207
}
208208
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { computed as _computed } from '@vue/reactivity'
22
import { isInSSRComponentSetup } from './component'
33

4-
export const computed = ((getterOrOptions: any, debugOptions?: any) => {
4+
export const computed: typeof _computed = (
5+
getterOrOptions: any,
6+
debugOptions?: any
7+
) => {
58
// @ts-ignore
69
return _computed(getterOrOptions, debugOptions, isInSSRComponentSetup)
7-
}) as typeof _computed
10+
}

packages/runtime-core/src/apiCreateApp.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,7 @@ export function createAppAPI<HostElement>(
330330
` you need to unmount the previous app by calling \`app.unmount()\` first.`
331331
)
332332
}
333-
const vnode = createVNode(
334-
rootComponent as ConcreteComponent,
335-
rootProps
336-
)
333+
const vnode = createVNode(rootComponent, rootProps)
337334
// store app context on the root VNode.
338335
// this will be set on the root instance on initial mount.
339336
vnode.appContext = context

packages/runtime-core/src/apiWatch.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import { DeprecationTypes } from './compat/compatConfig'
4343
import { checkCompatEnabled, isCompatEnabled } from './compat/compatConfig'
4444
import { ObjectWatchOptionItem } from './componentOptions'
4545
import { useSSRContext } from '@vue/runtime-core'
46-
import { SSRContext } from '@vue/server-renderer'
4746

4847
export type WatchEffect = (onCleanup: OnCleanup) => void
4948

@@ -297,7 +296,7 @@ function doWatch(
297296
])
298297
}
299298
if (flush === 'sync') {
300-
const ctx = useSSRContext() as SSRContext
299+
const ctx = useSSRContext()!
301300
ssrCleanup = ctx.__watcherHandles || (ctx.__watcherHandles = [])
302301
} else {
303302
return NOOP
@@ -318,9 +317,7 @@ function doWatch(
318317
deep ||
319318
forceTrigger ||
320319
(isMultiSource
321-
? (newValue as any[]).some((v, i) =>
322-
hasChanged(v, (oldValue as any[])[i])
323-
)
320+
? (newValue as any[]).some((v, i) => hasChanged(v, oldValue[i]))
324321
: hasChanged(newValue, oldValue)) ||
325322
(__COMPAT__ &&
326323
isArray(newValue) &&
@@ -461,7 +458,7 @@ export function traverse(value: unknown, seen?: Set<unknown>) {
461458
})
462459
} else if (isPlainObject(value)) {
463460
for (const key in value) {
464-
traverse((value as any)[key], seen)
461+
traverse(value[key], seen)
465462
}
466463
}
467464
return value

packages/runtime-core/src/component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export type ConcreteComponent<
161161
M extends MethodOptions = MethodOptions
162162
> =
163163
| ComponentOptions<Props, RawBindings, D, C, M>
164-
| FunctionalComponent<Props, any, any>
164+
| FunctionalComponent<Props, any>
165165

166166
/**
167167
* A type used in public APIs where a component type is expected.

packages/runtime-core/src/componentEmits.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export function emit(
173173
const onceHandler = props[handlerName + `Once`]
174174
if (onceHandler) {
175175
if (!instance.emitted) {
176-
instance.emitted = {} as Record<any, boolean>
176+
instance.emitted = {}
177177
} else if (instance.emitted[handlerName]) {
178178
return
179179
}

packages/runtime-core/src/componentOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ export function applyOptions(instance: ComponentInternalInstance) {
809809
if (isArray(hook)) {
810810
hook.forEach(_hook => register(_hook.bind(publicThis)))
811811
} else if (hook) {
812-
register((hook as Function).bind(publicThis))
812+
register(hook.bind(publicThis))
813813
}
814814
}
815815

@@ -885,7 +885,7 @@ export function resolveInjections(
885885
injectOptions = normalizeInject(injectOptions)!
886886
}
887887
for (const key in injectOptions) {
888-
const opt = (injectOptions as ObjectInjectOptions)[key]
888+
const opt = injectOptions[key]
889889
let injected: unknown
890890
if (isObject(opt)) {
891891
if ('default' in opt) {

packages/runtime-core/src/componentPublicInstance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ type ExtractMixin<T> = {
105105
}[T extends ComponentOptionsMixin ? 'Mixin' : never]
106106

107107
export type IntersectionMixin<T> = IsDefaultMixinComponent<T> extends true
108-
? OptionTypesType<{}, {}, {}, {}, {}>
108+
? OptionTypesType
109109
: UnionToIntersection<ExtractMixin<T>>
110110

111111
export type UnwrapMixinsType<

packages/runtime-core/src/hmr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ function updateComponentDef(
168168
extend(oldComp, newComp)
169169
for (const key in oldComp) {
170170
if (key !== '__file' && !(key in newComp)) {
171-
delete (oldComp as any)[key]
171+
delete oldComp[key]
172172
}
173173
}
174174
}

0 commit comments

Comments
 (0)