From: webfansplz <308241863@qq.com> Date: Mon, 3 Oct 2022 08:37:54 +0000 (+0800) Subject: refactor(types): improve of type assertion (#4177) X-Git-Tag: v3.2.41~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a9e3fa4e21c1f61479e2accde20087184ea6a355;p=thirdparty%2Fvuejs%2Fcore.git refactor(types): improve of type assertion (#4177) Co-authored-by: webfansplz <> --- diff --git a/packages/runtime-core/src/components/BaseTransition.ts b/packages/runtime-core/src/components/BaseTransition.ts index a671bef656..5e5e216d34 100644 --- a/packages/runtime-core/src/components/BaseTransition.ts +++ b/packages/runtime-core/src/components/BaseTransition.ts @@ -274,7 +274,7 @@ if (__COMPAT__) { // export the public type for h/tsx inference // also to avoid inline import() in generated d.ts files -export const BaseTransition = BaseTransitionImpl as any as { +export const BaseTransition = BaseTransitionImpl as unknown as { new (): { $props: BaseTransitionProps } diff --git a/packages/runtime-core/src/components/Suspense.ts b/packages/runtime-core/src/components/Suspense.ts index 8408cab388..baf5708862 100644 --- a/packages/runtime-core/src/components/Suspense.ts +++ b/packages/runtime-core/src/components/Suspense.ts @@ -89,7 +89,9 @@ export const SuspenseImpl = { } // Force-casted public typing for h and TSX props inference -export const Suspense = (__FEATURE_SUSPENSE__ ? SuspenseImpl : null) as any as { +export const Suspense = (__FEATURE_SUSPENSE__ + ? SuspenseImpl + : null) as unknown as { __isSuspense: true new (): { $props: VNodeProps & SuspenseProps } } diff --git a/packages/runtime-core/src/components/Teleport.ts b/packages/runtime-core/src/components/Teleport.ts index 06b69aff4e..e519aa2bb3 100644 --- a/packages/runtime-core/src/components/Teleport.ts +++ b/packages/runtime-core/src/components/Teleport.ts @@ -52,13 +52,13 @@ const resolveTarget = ( `ideally should be outside of the entire Vue component tree.` ) } - return target as any + return target as T } } else { if (__DEV__ && !targetSelector && !isTeleportDisabled(props)) { warn(`Invalid Teleport target: ${targetSelector}`) } - return targetSelector as any + return targetSelector as T } } @@ -388,7 +388,7 @@ function hydrateTeleport( } // Force-casted public typing for h and TSX props inference -export const Teleport = TeleportImpl as any as { +export const Teleport = TeleportImpl as unknown as { __isTeleport: true new (): { $props: VNodeProps & TeleportProps } } diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index c1b0773292..8e3020f9e3 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -100,7 +100,7 @@ const cacheStringFunction = string>(fn: T): T => { return ((str: string) => { const hit = cache[str] return hit || (cache[str] = fn(str)) - }) as any + }) as T } const camelizeRE = /-(\w)/g diff --git a/packages/template-explorer/src/index.ts b/packages/template-explorer/src/index.ts index d676c71737..3cf9c6b52c 100644 --- a/packages/template-explorer/src/index.ts +++ b/packages/template-explorer/src/index.ts @@ -275,5 +275,5 @@ function debounce any>( fn(...args) prevTimer = null }, delay) - }) as any + }) as T }