@meld-ts/core
    Preparing search index...

    Function isPresent

    • 检查值是否不为 null 且不为 undefined(非空断言)

      isNil 的逻辑取反。通过后 TS 从 T | null | undefined 中排除 nullundefined,收窄为 T

      Type Parameters

      • T

      Parameters

      • val: T | null | undefined

        — 待检查的值(类型为 T | null | undefined

      Returns val is T

      true 当且仅当 val 既非 null 也非 undefined,同时收窄为 T

      const value: string | null | undefined = 'hello';
      if (isPresent(value)) {
      value.toUpperCase(); // value: string
      }
      isPresent(null); // false
      isPresent(undefined); // false