Skip to content

isDefined

类别
导出体积
86 B
上次更改
last month

用于 Ref 的非空检查类型守卫。

用法

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>

源码

源码文档

贡献者

Anthony Fu
一纸忘忧
Anthony Fu
bjacobgordon-cy
Glen

更新日志

v11.0.0-beta.3 on 8/14/2024
fd884 - fix: moves most specific overload to the top (#4141)