Skip to content

isDefined

类别
导出体积
103 B
上次更改
5 months ago

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

用法

ts
import { 
isDefined
} from '@vueuse/core'
const
example
=
ref
(
Math
.
random
() ? 'example' :
undefined
) // Ref<string | undefined>
if (
isDefined
(
example
))
example
// Ref<string>

类型声明

ts
export type 
IsDefinedReturn
= boolean
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
Robin
James Garbutt
bjacobgordon-cy
Glen

更新日志

c1d6e - feat(shared): ensure return types exists (#4659)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
fd884 - fix: moves most specific overload to the top (#4141)