refactor(types): widen Component type to include consutructor types
returned from `defineComponent` ref: https://github.com/vuejs/vue-router-next/pull/421 also close #1880 Previous `Component` type is now exported as `ConcreteComponent`. This introduces a minor breaking change when calling `h(comp, { ... })` will now fail if `comp` is a of generic `Component` type, since it does not specify what props it expects.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {
|
||||
Component,
|
||||
ConcreteComponent,
|
||||
getCurrentInstance,
|
||||
FunctionalComponent,
|
||||
SetupContext,
|
||||
@@ -33,7 +33,7 @@ import {
|
||||
invokeVNodeHook
|
||||
} from '../renderer'
|
||||
import { setTransitionHooks } from './BaseTransition'
|
||||
import { ComponentRenderContext } from '../componentProxy'
|
||||
import { ComponentRenderContext } from '../componentPublicInstance'
|
||||
|
||||
type MatchPattern = string | RegExp | string[] | RegExp[]
|
||||
|
||||
@@ -43,7 +43,7 @@ export interface KeepAliveProps {
|
||||
max?: number | string
|
||||
}
|
||||
|
||||
type CacheKey = string | number | Component
|
||||
type CacheKey = string | number | ConcreteComponent
|
||||
type Cache = Map<CacheKey, VNode>
|
||||
type Keys = Set<CacheKey>
|
||||
|
||||
@@ -151,7 +151,7 @@ const KeepAliveImpl = {
|
||||
|
||||
function pruneCache(filter?: (name: string) => boolean) {
|
||||
cache.forEach((vnode, key) => {
|
||||
const name = getName(vnode.type as Component)
|
||||
const name = getName(vnode.type as ConcreteComponent)
|
||||
if (name && (!filter || !filter(name))) {
|
||||
pruneCacheEntry(key)
|
||||
}
|
||||
@@ -228,7 +228,7 @@ const KeepAliveImpl = {
|
||||
return vnode
|
||||
}
|
||||
|
||||
const comp = vnode.type as Component
|
||||
const comp = vnode.type as ConcreteComponent
|
||||
const name = getName(comp)
|
||||
const { include, exclude, max } = props
|
||||
|
||||
@@ -291,7 +291,7 @@ export const KeepAlive = (KeepAliveImpl as any) as {
|
||||
}
|
||||
}
|
||||
|
||||
function getName(comp: Component): string | void {
|
||||
function getName(comp: ConcreteComponent): string | void {
|
||||
return (comp as FunctionalComponent).displayName || comp.name
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user