Skip to content

isDefined

Category
Export Size
103 B
Last Changed
4 months ago

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>

Type Declarations

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>

Source

SourceDocs

Contributors

Anthony Fu
Anthony Fu
Robin
James Garbutt
bjacobgordon-cy
Glen

Changelog

v13.1.0 on
c1d6e - feat(shared): ensure return types exists (#4659)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v11.0.0-beta.3 on
fd884 - fix: moves most specific overload to the top (#4141)

Released under the MIT License.

FREE WEEKEND
48 Hours of Unlimited Official Vue.js Certification Training
Reserve Your Spot
23-24 August