Skip to content

isDefined ​

Category
Export Size
86 B
Last Changed
3 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 ​

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>

Source ​

Source • Docs

Contributors ​

Anthony Fu
Anthony Fu
bjacobgordon-cy
Glen

Changelog ​

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

Released under the MIT License.