Skip to content

Commit

Permalink
refactor(types): improve of type assertion (#4177)
Browse files Browse the repository at this point in the history
Co-authored-by: webfansplz <>
  • Loading branch information
webfansplz committed Oct 3, 2022
1 parent 3a13074 commit a9e3fa4
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/runtime-core/src/components/BaseTransition.ts
Expand Up @@ -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<any>
}
Expand Down
4 changes: 3 additions & 1 deletion packages/runtime-core/src/components/Suspense.ts
Expand Up @@ -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 }
}
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime-core/src/components/Teleport.ts
Expand Up @@ -52,13 +52,13 @@ const resolveTarget = <T = RendererElement>(
`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
}
}

Expand Down Expand Up @@ -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 }
}
2 changes: 1 addition & 1 deletion packages/shared/src/index.ts
Expand Up @@ -100,7 +100,7 @@ const cacheStringFunction = <T extends (str: string) => 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
Expand Down
2 changes: 1 addition & 1 deletion packages/template-explorer/src/index.ts
Expand Up @@ -275,5 +275,5 @@ function debounce<T extends (...args: any[]) => any>(
fn(...args)
prevTimer = null
}, delay)
}) as any
}) as T
}

0 comments on commit a9e3fa4

Please sign in to comment.