diff --git a/packages/compiler-core/src/transforms/transformExpression.ts b/packages/compiler-core/src/transforms/transformExpression.ts index 1c5d67ded..fa3ef6b35 100644 --- a/packages/compiler-core/src/transforms/transformExpression.ts +++ b/packages/compiler-core/src/transforms/transformExpression.ts @@ -183,7 +183,7 @@ export function processExpression( // range is offset by -1 due to the wrapping parens when parsed const start = id.start - 1 const end = id.end - 1 - const last = ids[i - 1] as any + const last = ids[i - 1] const leadingText = rawExp.slice(last ? last.end - 1 : 0, start) if (leadingText.length || id.prefix) { children.push(leadingText + (id.prefix || ``)) diff --git a/packages/runtime-core/src/apiApp.ts b/packages/runtime-core/src/apiApp.ts index 99ab5b78d..ecf26fabc 100644 --- a/packages/runtime-core/src/apiApp.ts +++ b/packages/runtime-core/src/apiApp.ts @@ -157,7 +157,9 @@ export function createAppAPI( `It will be overwritten with the new value.` ) } - context.provides[key as any] = value + // TypeScript doesn't allow symbols as index type + // https://github.com/Microsoft/TypeScript/issues/24587 + context.provides[key as string] = value } } diff --git a/packages/runtime-core/src/apiInject.ts b/packages/runtime-core/src/apiInject.ts index 3766d9f1c..7eb076f1a 100644 --- a/packages/runtime-core/src/apiInject.ts +++ b/packages/runtime-core/src/apiInject.ts @@ -20,7 +20,8 @@ export function provide(key: InjectionKey | string, value: T) { if (parentProvides === provides) { provides = currentInstance.provides = Object.create(parentProvides) } - provides[key as any] = value + // TS doesn't allow symbol as index type + provides[key as string] = value } } @@ -30,7 +31,8 @@ export function inject(key: InjectionKey | string, defaultValue?: any) { if (currentInstance) { const provides = currentInstance.provides if (key in provides) { - return provides[key as any] as any + // TS doesn't allow symbol as index type + return provides[key as string] } else if (defaultValue !== undefined) { return defaultValue } else if (__DEV__) { diff --git a/packages/runtime-core/src/apiOptions.ts b/packages/runtime-core/src/apiOptions.ts index 30b6521d4..fd3f2ff8d 100644 --- a/packages/runtime-core/src/apiOptions.ts +++ b/packages/runtime-core/src/apiOptions.ts @@ -185,7 +185,7 @@ export function applyOptions( instance.renderContext === EMPTY_OBJ ? (instance.renderContext = reactive({})) : instance.renderContext - const ctx = instance.renderProxy as any + const ctx = instance.renderProxy! const { // composition mixins, @@ -265,7 +265,7 @@ export function applyOptions( if (isString(raw)) { const handler = renderContext[raw] if (isFunction(handler)) { - watch(getter, handler as any) + watch(getter, handler as WatchHandler) } else if (__DEV__) { // TODO warn invalid watch handler path } diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 5371a8f59..8a72d6860 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -210,7 +210,7 @@ export function instanceWatch( cb: Function, options?: WatchOptions ): () => void { - const ctx = this.renderProxy as any + const ctx = this.renderProxy! const getter = isString(source) ? () => ctx[source] : source.bind(ctx) const stop = watch(getter, cb.bind(ctx), options) onBeforeUnmount(stop, this) diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index 75a2876aa..0cdbf04be 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -132,8 +132,8 @@ export function createComponentInstance( type: vnode.type as Component, root: null as any, // set later so it can point to itself next: null, - subTree: null as any, - update: null as any, + subTree: null as any, // will be set synchronously right after creation + update: null as any, // will be set synchronously right after creation render: null, renderProxy: null, propsProxy: null, diff --git a/packages/runtime-core/src/componentProxy.ts b/packages/runtime-core/src/componentProxy.ts index 49727b359..e02496ed3 100644 --- a/packages/runtime-core/src/componentProxy.ts +++ b/packages/runtime-core/src/componentProxy.ts @@ -15,6 +15,7 @@ export type ComponentPublicInstance< M = {}, PublicProps = P > = { + [key: string]: any $data: D $props: PublicProps $attrs: Data diff --git a/packages/runtime-core/src/componentRenderUtils.ts b/packages/runtime-core/src/componentRenderUtils.ts index 554430c54..cdd232ee9 100644 --- a/packages/runtime-core/src/componentRenderUtils.ts +++ b/packages/runtime-core/src/componentRenderUtils.ts @@ -40,7 +40,7 @@ export function renderComponentRoot( slots, emit }) - : render(props, null as any) + : render(props, null as any /* we know it doesn't it */) ) } } catch (err) { diff --git a/packages/runtime-core/src/componentSlots.ts b/packages/runtime-core/src/componentSlots.ts index 534caed5f..8399bd352 100644 --- a/packages/runtime-core/src/componentSlots.ts +++ b/packages/runtime-core/src/componentSlots.ts @@ -11,11 +11,16 @@ import { ShapeFlags } from './shapeFlags' import { warn } from './warning' export type Slot = (...args: any[]) => VNodeChildren -export type Slots = Readonly<{ + +export type InternalSlots = { [name: string]: Slot -}> +} + +export type Slots = Readonly + export type RawSlots = { [name: string]: unknown + _compiled?: boolean } const normalizeSlotValue = (value: unknown): VNode[] => @@ -40,17 +45,18 @@ export function resolveSlots( instance: ComponentInternalInstance, children: NormalizedChildren ) { - let slots: Slots | void + let slots: InternalSlots | void if (instance.vnode.shapeFlag & ShapeFlags.SLOTS_CHILDREN) { - if ((children as any)._compiled) { + const rawSlots = children as RawSlots + if (rawSlots._compiled) { // pre-normalized slots object generated by compiler slots = children as Slots } else { slots = {} - for (const key in children as RawSlots) { - let value = (children as RawSlots)[key] + for (const key in rawSlots) { + const value = rawSlots[key] if (isFunction(value)) { - ;(slots as any)[key] = normalizeSlot(key, value) + slots[key] = normalizeSlot(key, value) } else if (value != null) { if (__DEV__) { warn( @@ -58,8 +64,8 @@ export function resolveSlots( `Prefer function slots for better performance.` ) } - value = normalizeSlotValue(value) - ;(slots as any)[key] = () => value + const normalized = normalizeSlotValue(value) + slots[key] = () => normalized } } } diff --git a/packages/runtime-core/src/createRenderer.ts b/packages/runtime-core/src/createRenderer.ts index 2d230ec71..3a90d1e0f 100644 --- a/packages/runtime-core/src/createRenderer.ts +++ b/packages/runtime-core/src/createRenderer.ts @@ -1188,7 +1188,7 @@ export function createRenderer< nextVNode.component = instance instance.vnode = nextVNode instance.next = null - resolveProps(instance, nextVNode.props, (nextVNode.type as any).props) + resolveProps(instance, nextVNode.props, (nextVNode.type as Component).props) resolveSlots(instance, nextVNode.children) } diff --git a/packages/runtime-core/src/directives.ts b/packages/runtime-core/src/directives.ts index 09caf36be..e3f84dd70 100644 --- a/packages/runtime-core/src/directives.ts +++ b/packages/runtime-core/src/directives.ts @@ -104,7 +104,8 @@ export function applyDirectives(vnode: VNode, directives: DirectiveArguments) { vnode = cloneVNode(vnode) vnode.props = vnode.props != null ? extend({}, vnode.props) : {} for (let i = 0; i < directives.length; i++) { - ;(applyDirective as any)(vnode.props, instance, ...directives[i]) + const [dir, value, arg, modifiers] = directives[i] + applyDirective(vnode.props, instance, dir, value, arg, modifiers) } } else if (__DEV__) { warn(`applyDirectives can only be used inside render functions.`) diff --git a/packages/runtime-core/src/suspense.ts b/packages/runtime-core/src/suspense.ts index 09a067ab0..c852f424b 100644 --- a/packages/runtime-core/src/suspense.ts +++ b/packages/runtime-core/src/suspense.ts @@ -1,7 +1,8 @@ -import { VNode, normalizeVNode } from './vnode' +import { VNode, normalizeVNode, VNodeChild } from './vnode' import { ShapeFlags } from '.' import { isFunction } from '@vue/shared' import { ComponentInternalInstance } from './component' +import { Slots } from './componentSlots' export const SuspenseSymbol = __DEV__ ? Symbol('Suspense key') : Symbol() @@ -62,14 +63,14 @@ export function normalizeSuspenseChildren( } { const { shapeFlag, children } = vnode if (shapeFlag & ShapeFlags.SLOTS_CHILDREN) { - const { default: d, fallback } = children as any + const { default: d, fallback } = children as Slots return { content: normalizeVNode(isFunction(d) ? d() : d), fallback: normalizeVNode(isFunction(fallback) ? fallback() : fallback) } } else { return { - content: normalizeVNode(children as any), + content: normalizeVNode(children as VNodeChild), fallback: normalizeVNode(null) } } diff --git a/packages/runtime-dom/src/modules/events.ts b/packages/runtime-dom/src/modules/events.ts index 7674f69b5..7d572e491 100644 --- a/packages/runtime-dom/src/modules/events.ts +++ b/packages/runtime-dom/src/modules/events.ts @@ -5,9 +5,9 @@ import { } from '@vue/runtime-core' import { ErrorCodes } from 'packages/runtime-core/src/errorHandling' -interface Invoker extends Function { +interface Invoker extends EventListener { value: EventValue - lastUpdated?: number + lastUpdated: number } type EventValue = (Function | Function[]) & { @@ -58,7 +58,7 @@ export function patchEvent( el.addEventListener(name, createInvoker(nextValue, instance)) } } else if (invoker) { - el.removeEventListener(name, invoker as any) + el.removeEventListener(name, invoker) } } @@ -66,7 +66,7 @@ function createInvoker( initialValue: any, instance: ComponentInternalInstance | null ) { - const invoker = ((e: Event) => { + const invoker: Invoker = (e: Event) => { // async edge case #6566: inner click event triggers patch, event handler // attached to outer element during patch, and triggered again. This // happens because browsers fire microtask ticks between event propagation. @@ -94,7 +94,7 @@ function createInvoker( ) } } - }) as any + } invoker.value = initialValue initialValue.invoker = invoker invoker.lastUpdated = getNow()