Skip to content

isDefined

Ref 的非无效检查类型保护。

¥Non-nullish checking type guard for Ref.

用法

¥Usage

ts
import { isDefined } from '@vueuse/core'

const example = ref(Math.random() ? 'example' : undefined) // Ref<string | undefined>

if (isDefined(example))
  example // Ref<string>

类型声明

typescript
export declare function isDefined<T>(
  v: ComputedRef<T>,
): v is ComputedRef<Exclude<T, null | undefined>>
export declare function isDefined<T>(
  v: Ref<T>,
): v is Ref<Exclude<T, null | undefined>>
export declare function isDefined<T>(v: T): v is Exclude<T, null | undefined>

源代码

源代码文档

变更日志

No recent changes

VueUse 中文网 - 粤ICP备13048890号