Function isPathNotNil

  • Checks whether the given property path contains null or undefined within the given object. Narrows the type of each property in the path from T | null | undefined to T.

    There are two variants:

    A simple function for direct calls (e.g. in if-statement-conditions). It asks for the object to check as well as the property path.

    The second variant is a factory-function which only gets the property path. It returns a pre-configured predicate function for usage with functional calls like Array#filter.

    Both variants have overloads with up to 5 properties to check.

    Example:

    const x: { a: { b: number | undefined } } = { a: { b: 1 } };

    // simple usage: pass object and property path
    if (isPathNotNil(x, 'a', 'b')) {
    // type of x is now { a: { b: number } }
    x.a.b.toFixed(3); // safe to access a and b
    }

    // array usage: just pass the properties to check
    [x]
    .filter(isPathNotNil('a', 'b'))
    // type is now [{ a: { b: number } }]
    .map(x => x.a.b.toFixed(3)) // safe to access a and b

    With a path of just one property it does the same as isPropertyNotNil.

    Type Parameters

    • O extends object

    • P1 extends string | number | symbol

    Parameters

    • obj: O
    • p1: P1

    Returns obj is PathNotNil_1<O, P1> & O

  • Type Parameters

    • O extends object

    • P1 extends string | number | symbol

    • P2 extends string | number | symbol

    Parameters

    • obj: O
    • p1: P1
    • p2: P2

    Returns obj is PathNotNil_2<O, P1, P2> & O

  • Type Parameters

    • O extends object

    • P1 extends string | number | symbol

    • P2 extends string | number | symbol

    • P3 extends string | number | symbol

    Parameters

    • obj: O
    • p1: P1
    • p2: P2
    • p3: P3

    Returns obj is PathNotNil_3<O, P1, P2, P3> & O

  • Type Parameters

    • O extends object

    • P1 extends string | number | symbol

    • P2 extends string | number | symbol

    • P3 extends string | number | symbol

    • P4 extends string | number | symbol

    Parameters

    • obj: O
    • p1: P1
    • p2: P2
    • p3: P3
    • p4: P4

    Returns obj is PathNotNil_4<O, P1, P2, P3, P4> & O

  • Type Parameters

    • O extends object

    • P1 extends string | number | symbol

    • P2 extends string | number | symbol

    • P3 extends string | number | symbol

    • P4 extends string | number | symbol

    • P5 extends string | number | symbol

    Parameters

    • obj: O
    • p1: P1
    • p2: P2
    • p3: P3
    • p4: P4
    • p5: P5

    Returns obj is PathNotNil_5<O, P1, P2, P3, P4, P5> & O

  • Type Parameters

    • O extends object

    • P1 extends string | number | symbol

    Parameters

    • p1: P1

    Returns ((obj) => obj is PathNotNil_1<O, P1> & O)

      • (obj): obj is PathNotNil_1<O, P1> & O
      • Parameters

        • obj: O

        Returns obj is PathNotNil_1<O, P1> & O

  • Type Parameters

    • O extends object

    • P1 extends string | number | symbol

    • P2 extends string | number | symbol

    Parameters

    • p1: P1
    • p2: P2

    Returns ((obj) => obj is PathNotNil_2<O, P1, P2> & O)

      • (obj): obj is PathNotNil_2<O, P1, P2> & O
      • Parameters

        • obj: O

        Returns obj is PathNotNil_2<O, P1, P2> & O

  • Type Parameters

    • O extends object

    • P1 extends string | number | symbol

    • P2 extends string | number | symbol

    • P3 extends string | number | symbol

    Parameters

    • p1: P1
    • p2: P2
    • p3: P3

    Returns ((obj) => obj is PathNotNil_3<O, P1, P2, P3> & O)

      • (obj): obj is PathNotNil_3<O, P1, P2, P3> & O
      • Parameters

        • obj: O

        Returns obj is PathNotNil_3<O, P1, P2, P3> & O

  • Type Parameters

    • O extends object

    • P1 extends string | number | symbol

    • P2 extends string | number | symbol

    • P3 extends string | number | symbol

    • P4 extends string | number | symbol

    Parameters

    • p1: P1
    • p2: P2
    • p3: P3
    • p4: P4

    Returns ((obj) => obj is PathNotNil_4<O, P1, P2, P3, P4> & O)

      • (obj): obj is PathNotNil_4<O, P1, P2, P3, P4> & O
      • Parameters

        • obj: O

        Returns obj is PathNotNil_4<O, P1, P2, P3, P4> & O

  • Type Parameters

    • O extends object

    • P1 extends string | number | symbol

    • P2 extends string | number | symbol

    • P3 extends string | number | symbol

    • P4 extends string | number | symbol

    • P5 extends string | number | symbol

    Parameters

    • p1: P1
    • p2: P2
    • p3: P3
    • p4: P4
    • p5: P5

    Returns ((obj) => obj is PathNotNil_5<O, P1, P2, P3, P4, P5> & O)

      • (obj): obj is PathNotNil_5<O, P1, P2, P3, P4, P5> & O
      • Parameters

        • obj: O

        Returns obj is PathNotNil_5<O, P1, P2, P3, P4, P5> & O

Generated using TypeDoc