isPathNotNil<O, P1>(obj, p1): obj is PathNotNil_1<O, P1> & O
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.
// 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
isPathNotNil<O, P1, P2>(obj, p1, p2): obj is PathNotNil_2<O, P1, P2> & 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
isPathNotNil<O, P1, P2, P3>(obj, p1, p2, p3): 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
Parameters
obj: O
p1: P1
p2: P2
p3: P3
Returns obj is PathNotNil_3<O, P1, P2, P3> & O
isPathNotNil<O, P1, P2, P3, P4>(obj, p1, p2, p3, p4): 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
Parameters
obj: O
p1: P1
p2: P2
p3: P3
p4: P4
Returns obj is PathNotNil_4<O, P1, P2, P3, P4> & O
Checks whether the given property path contains
null
orundefined
within the given object. Narrows the type of each property in the path fromT | null | undefined
toT
.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:
With a path of just one property it does the same as isPropertyNotNil.