@jenova-marie/ts-rust-result - v2.2.12
    Preparing search index...

    Function assertNotNil

    • Asserts that a value is not null or undefined, returning the value if valid.

      Type Parameters

      • T

        The type of the value

      • E = Error

        The type of the error (defaults to Error)

      Parameters

      • value: undefined | null | T

        The value to check for null/undefined

      • message: string = 'Expected value to be non-null'

        Custom error message

      • shouldThrow: boolean = true

        Whether to throw the error instead of returning a Result (defaults to true)

      Returns Result<NonNullable<T>, E>

      A Result containing the value if not null/undefined, or an error if it is

      If shouldThrow is true and value is null/undefined

      const nameCheck = assertNotNil(user.name)
      if (!nameCheck.ok) return nameCheck
      const name = nameCheck.value // TypeScript knows this is not null