An OptionalLens<T, P> grants type-safe access on potential P, hence it can be used to
get P | undefined from an arbitrary T, where T might be a union of arbitrary types.
From an OptionalLens<T, P>, you can also retrieve a new OptionalLens<P, P[K]>, where K is a potential key of P.
Use getLens<T>() to get an initial OptionalLens<T, T>.
You can see OptionalLens as "universal optional chaining". While normal optional chaining only works on a T | null | undefined,
the OptionalLens allows the type-safe access on arbitrary unions.
An
OptionalLens<T, P>
grants type-safe access on potentialP
, hence it can be used to getP | undefined
from an arbitraryT
, whereT
might be a union of arbitrary types.From an
OptionalLens<T, P>
, you can also retrieve a newOptionalLens<P, P[K]>
, where K is a potential key of P. UsegetLens<T>()
to get an initialOptionalLens<T, T>
.You can see
OptionalLens
as "universal optional chaining". While normal optional chaining only works on aT | null | undefined
, theOptionalLens
allows the type-safe access on arbitrary unions.E.g. given the following type and values:
you could get the following results with optional-lenses: