Skip to content
On this page

isDefined

Category
Last Changed
7 months ago

Non-nullish checking type guard for Ref.

Usage

import { isDefined } from '@vueuse/core'

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

if (isDefined(example))
  example // Ref<string>
import { isDefined } from '@vueuse/core'

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

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

Type Declarations

export declare function isDefined<T>(
  v: Ref<T>
): v is Ref<Exclude<T, null | undefined>>
export declare function isDefined<T>(
  v: ComputedRef<T>
): v is ComputedRef<Exclude<T, null | undefined>>
export declare function isDefined<T>(v: T): v is 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: ComputedRef<T>
): v is ComputedRef<Exclude<T, null | undefined>>
export declare function isDefined<T>(v: T): v is Exclude<T, null | undefined>

Source

SourceDocs

Contributors

Anthony Fu
Glen

Changelog

v6.6.0 on 10/16/2021
b9e80 - feat: new function (#812)
isDefined has loaded