All files / src is-defined.ts

87.5% Statements 7/8
100% Branches 2/2
100% Functions 2/2
87.5% Lines 7/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 2022x               90x 127x 13x   114x 114x   114x        
import { isObject } from './is-object.js'
 
export type Defined<T> =
  T extends undefined ?
    never :
    T
 
/** @returns true if values propagates to undefined, false otherwise. */
export function isDefined<T>(value: T): value is Defined<T> {
  if (typeof value === 'undefined') {
    return false
  }
  if (isObject(value)) {
    return Object
      .values(value)
      .some(_ => typeof _ !== 'undefined')
  }
  return true
}