Function assertExists

  • Make an assertion that actual is not null or undefined. If not then throw.

    Type Parameters

    • T

      The type of the actual value.

    Parameters

    • actual: T

      The actual value to check.

    • Optionalmsg: string

      The optional message to include in the error if the assertion fails.

    Returns asserts actual is NonNullable<T>

    import { assertExists } from "@std/assert";

    assertExists("something"); // Doesn't throw
    assertExists(undefined); // Throws